android 内部存储自定义文件夹写入
try {
f = new File(this.getFilesDir().toString() + File.separator + "texts" + File.separator + 1 + ".txt");
fos = new FileOutputStream(f);
fos.write("test".getBytes());
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
代码中f生成的路径是 data/data/com../files/texts/1.txt , 运行中不抛出任何异常,但是文件却并没有被创建。
请问如何才能实现在internal storage中 自定义文件夹 并在文件夹中进行文件操作呢?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
FileOutputStream 不依赖文件是否存在,如果存在就打开文件,不存在就创建文件并打开。
问题原因可能在于"texts"目录没有创建和File.toString()。
没有亲测,请自己尝试。
确定没抛出任何异常?
@旱獭先生 正解。文件夹不存在的时候,请先创建目录