여기에서 문제가 무엇인지 알 수 없으므로 더 이상 작동하지 않습니다. URL에서 파일을 다운로드하려고합니다. 파일을 제대로 만들지 못하는 것 같습니다.파일을 다운로드 할 때 Java.io.FileNotFoundException이 발생합니다.
static String PATH = Environment.getExternalStorageDirectory() + "/Android/data/com.xxxx.xxxx/";
url = new URL("http://xxxxxxx.xxx/file.apk");
HttpURLConnection c = (HttpURLConnection) url.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(false);
c.connect();
File file = new File(PATH);
File outputFile = new File(file, "update"+separated[1]+".apk");
//it crashes at this point
FileOutputStream fos = new FileOutputStream(outputFile);
InputStream is = c.getInputStream();
byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = is.read(buffer)) != -1) {
fos.write(buffer, 0, len1);
}
fos.close();
is.close();
java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.xxxxx.xxx/update150.apk: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:409)
at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
at java.io.FileOutputStream.<init>(FileOutputStream.java:73)
at com.sanisidrolsa.appterris.GcmIntentService.onHandleIntent(GcmIntentService.java:67)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.os.HandlerThread.run(HandlerThread.java:61)
Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
at libcore.io.IoBridge.open(IoBridge.java:393)
... 7 more
올바른 위치에 파일이 올바르게 다운로드되고 파일 이름이 올바른지 수동으로 확인 했습니까? 두 번 확인해주세요. –
'file.mkdirs();'아마도 디렉토리를 만들 수 있을까요? –
변경 FileOutputStream fos = 새 FileOutputStream (출력 파일); OutputStream에 fos = 새로운 FileOutputStream (출력 파일); –