I download files from FTP and store them in cache
directory using path_provider
package
Future<void> _fileMock(String strFileName) async {
try {
final Directory appDocDir = await getTemporaryDirectory()..createSync(recursive: true);
String appDocPath = appDocDir.path;
print('appDocPath : $appDocPath');
_file = File('$appDocPath/$strFileName');
setSavePath('$appDocPath/$strFileName');
print('file : $file');
}catch(e){
print('_fileMock Error : ${e.toString()}');
final File file = File('');
}
}
The path to the cache
directory is /data/user/0/package name/cache/fileName
The file will download normally.
I want to copy or download files from the cache
directory to the download directory. Attach an image.
Solved
Implement in JAVA and call with MethodChannel.
///JAVA
Map<String, String> arg = call.arguments();
String strPath = arg.get("path");
String strFileName = arg.get("fileName");
assert strPath != null;
File fP02 = new File(strPath);
File file;
try {
assert strFileName != null;
file = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS), strFileName);
Files.copy(fP02.toPath(), file.toPath(), StandardCopyOption.REPLACE_EXISTING);
result.success(file.getPath());
} catch (IOException e) {
e.printStackTrace();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.