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中 自定义文件夹 并在文件夹中进行文件操作呢?
FileOutputStream 不依赖文件是否存在,如果存在就打开文件,不存在就创建文件并打开。
问题原因可能在于"texts"目录没有创建和File.toString()。
没有亲测,请自己尝试。