2

現在、Web アーカイブを保存して FileInputStream として取得するための次のコードがあります。ただし、webContent 内のチャネルは null のままで、FileNotFoundException がスローされます。

        // Save the Web Archive once loading is finished
        String path = context.getFilesDir().getAbsolutePath()
                + File.separator + WEB_PREFIX + postId;
        webView.saveWebArchive(path);
        FileInputStream webContent = null;
        try {
            webContent = context.openFileInput(WEB_PREFIX + postId);
        } catch (FileNotFoundException e) {
            Log.d("onPageFinished()", "FileNotFoundException");
            e.printStackTrace();
        }

代わりに context.openFileInput(path) を実行しようとすると、

09-05 23:39:42.448: E/AndroidRuntime(8399): java.lang.IllegalArgumentException: File /data/data/com.example/files/web-2189241737372651547 contains a path separator

誰かが解決策を知っていますか? 前の行でファイルを保存したので、ファイルは確かに存在します。

4

1 に答える 1

4

openFileInput()パスは受け付けません。パスにアクセスする場合はファイル名のみです。

代わりにこれを使用してください:

File file = new File(this.getFilesDir().getAbsolutePath() + (WEB_PREFIX + postId));

編集: 同じ場所からファイルを保存および取得していることを確認する必要があります。これを試してください:

注:必要かどうかは わかりませんがFile.separator、それを使用して、または使用せずに試して、どちらが機能するかを確認してください。

 String path = context.getFilesDir().getAbsolutePath()
                + File.separator + WEB_PREFIX + postId;
        webView.saveWebArchive(path);
        FileInputStream webContent = null;
        try {
            webContent = new File(path);
        } catch (FileNotFoundException e) {
            Log.d("onPageFinished()", "FileNotFoundException");
            e.printStackTrace();
        }
于 2013-09-06T03:52:54.303 に答える