Skip to content

Commit 5837361

Browse files
author
adamburnett
committed
Fixed file moving
1 parent fb0c5f1 commit 5837361

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -599,16 +599,36 @@ static void mv(String path, String dest, Callback callback) {
599599
callback.invoke("Source file at path `" + path + "` does not exist");
600600
return;
601601
}
602+
603+
//Check if the output file directory exists.
604+
File dir = new File(dest);
605+
if (!dir.exists())
606+
{
607+
dir.mkdirs();
608+
}
609+
602610
try {
603-
boolean result = src.renameTo(new File(dest));
604-
if (!result) {
605-
callback.invoke("mv failed for unknown reasons");
606-
return;
611+
InputStream in = new FileInputStream(path);
612+
OutputStream out = new FileOutputStream(dest);
613+
614+
//read source path to byte buffer. Write from input to output stream
615+
byte[] buffer = new byte[1024];
616+
int read;
617+
while ((read = in.read(buffer)) != -1) { //read is successful
618+
out.write(buffer, 0, read);
607619
}
620+
in.close();
621+
out.flush();
622+
623+
src.delete(); //remove original file
624+
} catch (FileNotFoundException exception) {
625+
callback.invoke(exception.toString());
626+
return;
608627
} catch (Exception e) {
609-
callback.invoke(e.getLocalizedMessage());
628+
callback.invoke(e.toString());
610629
return;
611630
}
631+
612632
callback.invoke();
613633
}
614634

0 commit comments

Comments
 (0)