“如何修复”;FileSystemException:无法打开文件";在读写文件时是否在颤振?
我对飞镖/颤振还很陌生,所以如果有什么我可以澄清的,请告诉我。我正在尝试下载一个文件,但当我尝试访问它时,会出现错误“FileSystemException:无法打开文件,路径=”./data.csv(操作系统错误:只读文件系统,错误号=30)”,我做错了什么,如何修复“如何修复”;FileSystemException:无法打开文件";在读写文件时是否在颤振?,file,flutter,dart,download,File,Flutter,Dart,Download,我对飞镖/颤振还很陌生,所以如果有什么我可以澄清的,请告诉我。我正在尝试下载一个文件,但当我尝试访问它时,会出现错误“FileSystemException:无法打开文件,路径=”./data.csv(操作系统错误:只读文件系统,错误号=30)”,我做错了什么,如何修复 downloadTextFile() { HttpClient client = new HttpClient(); client.getUrl(Uri.parse(*I put the link I used
downloadTextFile() {
HttpClient client = new HttpClient();
client.getUrl(Uri.parse(*I put the link I used here, but it's sort of long*))
.then((HttpClientRequest request) {
return request.close();
})
.then((HttpClientResponse response) {
response.pipe(new File('./data.csv').openWrite());
});
readFileByLines();
}
void readFileByLines() {
File file = new File('./data.csv');
List<String> lines = file.readAsLinesSync();
lines.forEach((l) => print(l));
}
downloadTextFile(){
HttpClient=新的HttpClient();
getUrl(Uri.parse(*我把我在这里使用的链接放在这里,但它有点长*)
.然后((HttpClientRequest请求){
返回请求。close();
})
.然后((HttpClientResponse响应){
response.pipe(新文件('./data.csv').openWrite());
});
readFileByLines();
}
void readFileByLines(){
File File=新文件('./data.csv');
List lines=file.readAsLinesSync();
行。forEach((l)=>打印(l));
}
您可以使用软件包并将文件写入
tempPath
或appDocPath
Directory tempDir = await getTemporaryDirectory();
String tempPath = tempDir.path;
Directory appDocDir = await getApplicationDocumentsDirectory();
String appDocPath = appDocDir.path;
对于Android,您可以在AndroidManifest.xml
中添加权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>