Skip to content

Commit c4a9189

Browse files
committed
fix: correct in/out flow in CopyFileTask
1 parent 2875d0c commit c4a9189

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

android/src/main/java/com/rnfs/RNFSManager.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -404,12 +404,14 @@ protected void onPostExecute (Exception ex) {
404404

405405
private class CopyFileTask extends AsyncTask<String, Void, Exception> {
406406
protected Exception doInBackground(String... paths) {
407+
InputStream in = null;
408+
OutputStream out = null;
407409
try {
408410
String filepath = paths[0];
409411
String destPath = paths[1];
410412

411-
InputStream in = getInputStream(filepath);
412-
OutputStream out = getOutputStream(destPath, false);
413+
in = getInputStream(filepath);
414+
out = getOutputStream(destPath, false);
413415

414416
byte[] buffer = new byte[1024];
415417
int length;
@@ -420,12 +422,14 @@ protected Exception doInBackground(String... paths) {
420422
} catch (Exception ex) {
421423
return ex;
422424
} finally {
423-
if (in != null) {
424-
in.close();
425-
}
426-
if (out != null) {
427-
out.close();
428-
}
425+
try {
426+
if (in != null) {
427+
in.close();
428+
}
429+
if (out != null) {
430+
out.close();
431+
}
432+
} catch (Exception ignored) { }
429433
}
430434
}
431435
}

0 commit comments

Comments
 (0)