2013-09-06 2 views
2

현재 웹 보관 파일을 저장 한 다음 FileInputStream으로 가져 오는 다음 코드가 있습니다. 그러나, 웹 콘텐츠 내에서 채널은 널 (null) 남아 FileNotFoundException이가 발생합니다 :저장된 파일에 액세스하려고 할 때 context.openFileInput()이 null을 반환합니다.

 // 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 (경로)를 수행하려는 경우 대신, 내가

이 가
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

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(); 
     } 
+0

답장을 보내 주셔서 감사합니다. 나는 그것을 시도하고 "webContent = new FileInputStream (path);", 그러나 그들은 둘 다 FileNotFoundException을 제공합니다. – cheese1756

+0

@ cheese1756 내 편집을 확인하십시오. – nedaRM

+0

나는 당신의 편집을 시도했다. 파일이 null이 아닙니다 (위대입니다!) 경로는 문자열에 지정된 경로와 같습니다. 나는 또한 adb를 확인하고 그 파일이 실제로 거기에 있다는 것을 확인했다 (그것은!). 남은 유일한 질문은 "webContent = new FileInputStream (path);"입니다. File이 작동하지 않습니다. – cheese1756

관련 문제