android内部存储如何自定义路径

2025-02-23 01:25:59
推荐回答(1个)
回答1:

获取getFilesDir()的父目录,然后只要不越过包名,它的子目录应该都能读写。

		File dataDir = getFilesDir().getParentFile();
File mydir = new File(dataDir, "aaa");
mydir.mkdir();
File file = new File(mydir, "test.txt");
BufferedWriter fw = null;
try {
file.createNewFile();
fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, true), "UTF-8"));
fw.append("测试内容");
fw.flush();
fw.close();
} catch (Exception e) {
e.printStackTrace();
}