- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我尝试在内部驱动器上生成一些文件时遇到此错误。下面是打印栈
03-27 01:36:16.111: W/System.err(1445): java.io.FileNotFoundException: /data/data/dev.shaw.MyShoppingPlanner/files/Stores/Giant_314_Horsham_Rd.txt: open failed: ENOTDIR (Not a directory)
代码
private void generateFiles() throws IOException {
File storelist = new File(this.getFilesDir() + File.separator +"Stores");
File listnames = new File(this.getFilesDir() + File.separator + "Lists");
listnames.mkdirs();
storelist.mkdirs();
//generate the store list, (Store Name) (street# Street la./rd./ave./etc.) (City/Town State ZipCode)
String stores[] ={"Giant Foodstore 314 Horsham Rd. Horsham Pa. 19044", "Acme Food 200 Blair Mill Rd. Horsham Pa. 19044"};
String lnames[] = {"Default List"};
String Dstorepath = storelist+File.separator + "Giant_314_Horsham_Rd.txt";
String Dlistpath = listnames + File.separator + "Default_List.txt";
File sample_store = new File(Dstorepath);
File sample_list = new File(Dlistpath);
FileOutputStream fos = new FileOutputStream(sample_store);
fos.write(stores[0].getBytes());
Toast.makeText(this,"Store File Generated" , Toast.LENGTH_SHORT).show();
fos = new FileOutputStream(sample_list);
fos.write(lnames[0].getBytes());
Toast.makeText(this,"List File Generated" , Toast.LENGTH_SHORT).show();
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}
最佳答案
尝试检查文件夹是否存在。
例如)
File listnames = new File(this.getFilesDir() + File.separator + "Lists");
if( !listnames.exists() )
listnames.mkdirs();
else if( !listnames.isDirectory() && listnames.canWrite() ){
listnames.delete();
listnames.mkdirs();
}
else{
//you can't access there with write permission.
//Try other way.
}
关于java - 安卓打开失败: ENOTDIR (Not a directory),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22676667/
我尝试在内部驱动器上生成一些文件时遇到此错误。下面是打印栈 03-27 01:36:16.111: W/System.err(1445): java.io.FileNotFoundException:
strerror() 函数返回简短的错误描述,将错误编号作为参数。例如,如果参数为ENOTDIR,则返回“Not a directory”,如果参数为EBUSY,则返回“Device or resou
我对 Node.js 非常陌生,并尝试使用 npm 安装 Flatiron,但它给了我一个错误。 sudo npm install flatiron -g 我得到 - npm http GET htt
所以我正在使用第三方项目,并且有以下代码块: // walk through /run and remove all filecontents, keeping 1 level directories
我发现 mapreduce 作业似乎由于 RawLocalFileSystem 中的某些问题而无法启动。 我该如何调试这个错误?似乎没有与 NativeIO chmod 异常关联的目录或命令的踪迹。
我将 VSCode 与 TSLint (v5.11.0) 结合使用。 我将 VSCode 设置为:“tslint.autoFixOnSave”:true但是,每当我打开任何 ts 文件时,我都会在输出
我正在使用html-pdf@2.1.0在我的 meteor 应用程序中。当 .create() 调用时,会生成以下错误。 最初它可以工作,但更新 Mac Sierra 后会生成以下错误。但是它可以在
我正在编写一个上传图像并将其移动到“./uploads”文件夹的脚本。这在我的本地计算机上运行良好,但今晚刚刚首次将项目部署到 EC2 实例,并且遇到了一个非常奇怪的问题。尝试上传图像时,服务器返回以
每次我尝试在我的 Windows10 MeteorJS 应用程序上添加一个新包,例如通过命令:meteor add iron:router(其他包同理) 我收到以下错误: C:\Users\Alek
我在我的 express-js 项目中使用 mongodb。我正在尝试在 vs code 中运行服务器,但它抛出 npm 包错误。它可以与 Webstorm 和 命令行 配合使用。 Error: EN
我正在电子中使用 html-pdf 从 html 生成 pdf。 当我通过“npm run start”测试时它有效。我可以得到pdf。 但是当我通过电子构建器将电子应用程序打包为.dmg文件时, 调
注意:我有最新的 npm 和 Node 版本。我已经尝试了 npm install error ENOTDIR 中提供的答案但对我不起作用。 我需要在 NodeRed 上安装 2 个 npm 模块作为
我正在 Windows 8 机器上的 homestead 上运行 Laravel 应用程序。 我使用 gulp、elixix 和 node.js 来编译 SASS 和 .js 文件等资源文件。 当我运
我是一名优秀的程序员,十分优秀!