android file.createNewFile() 报错 No such file or directory
W/System.err: java.io.IOException: No such file or directory
W/System.err: at java.io.UnixFileSystem.createFileExclusively0(Native Method)
W/System.err: at java.io.UnixFileSystem.createFileExclusively(UnixFileSystem.java:317)
W/System.err: at java.io.File.createNewFile(File.java:1008)
W/System.err: at com.zpd.testservice.utils.MyLogger.writeLogtoFile(MyLogger.java:273)
W/System.err: at com.zpd.testservice.utils.MyLogger.e(MyLogger.java:208)
W/System.err: at com.zpd.testservice.MyService$TestOutNetRunnable.run(MyService.java:126)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
W/System.err: at java.lang.Thread.run(Thread.java:919)
在Android10系统中,创建文件 报错, 目录未创建成功,导致文件未生成,创建文件夹路径方式:filePath.mkdirs(), 创建文件方式: file.createNewFile(); 检查未发现错误。
// 创建文件夹
if (!filePath.exists()) { filePath.mkdirs(); }
// 创建文件方式
if (!file.exists()) { file.createNewFile(); }
最后在AndroidManifest.xml 文件 application 中增加属性:
android:requestLegacyExternalStorage="true"
后正常了。
推荐阅读
-
文件上传报错:Unknown: file created in the system's temporary directory
-
报错android.view.InflateException: Binary XML file line #11: Attempt to invoke virtual method 'boolean怎么解决?
-
PHP创建文件目录报错mkdir(): No such file or directory解决方法
-
shopex主机报错误请求解决方案(No such file or directory)
-
Android7.0读取图片导致Uri.fromFile(File)报错
-
报错:/usr/bin/env: php: No such file or directory
-
Django报错:python: can‘t open file ‘manage.py‘: [Errno 2] No such file or directory
-
Gitlab 备份迁移恢复报错gtar: .: Cannot mkdir: No such file or directory
-
oracle报错cat: /etc/oratab: No such file or directory
-
报错:libmysqlclient.so.18: cannot open shared object file: No such file or directory.