mirror of
https://github.com/status-im/react-native-fs.git
synced 2025-03-01 07:20:33 +00:00
commit
e071c35999
@ -1,5 +1,6 @@
|
|||||||
package com.rnfs;
|
package com.rnfs;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
@ -125,9 +126,13 @@ public class RNFSManager extends ReactContextBaseJavaModule {
|
|||||||
@ReactMethod
|
@ReactMethod
|
||||||
public void moveFile(String filepath, String destPath, Promise promise) {
|
public void moveFile(String filepath, String destPath, Promise promise) {
|
||||||
try {
|
try {
|
||||||
File from = new File(filepath);
|
File inFile = new File(filepath);
|
||||||
File to = new File(destPath);
|
|
||||||
from.renameTo(to);
|
if (!inFile.renameTo(new File(destPath))) {
|
||||||
|
copyFile(filepath, destPath);
|
||||||
|
|
||||||
|
inFile.delete();
|
||||||
|
}
|
||||||
|
|
||||||
promise.resolve(true);
|
promise.resolve(true);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
@ -139,6 +144,16 @@ public class RNFSManager extends ReactContextBaseJavaModule {
|
|||||||
@ReactMethod
|
@ReactMethod
|
||||||
public void copyFile(String filepath, String destPath, Promise promise) {
|
public void copyFile(String filepath, String destPath, Promise promise) {
|
||||||
try {
|
try {
|
||||||
|
copyFile(filepath, destPath);
|
||||||
|
|
||||||
|
promise.resolve(null);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
reject(promise, filepath, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void copyFile(String filepath, String destPath) throws IOException {
|
||||||
InputStream in = new FileInputStream(filepath);
|
InputStream in = new FileInputStream(filepath);
|
||||||
OutputStream out = new FileOutputStream(destPath);
|
OutputStream out = new FileOutputStream(destPath);
|
||||||
|
|
||||||
@ -149,12 +164,6 @@ public class RNFSManager extends ReactContextBaseJavaModule {
|
|||||||
}
|
}
|
||||||
in.close();
|
in.close();
|
||||||
out.close();
|
out.close();
|
||||||
|
|
||||||
promise.resolve(null);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
reject(promise, filepath, ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReactMethod
|
@ReactMethod
|
||||||
|
Loading…
x
Reference in New Issue
Block a user