【发布时间】:2016-04-09 05:19:47
【问题描述】:
我开发了一个应用程序 - 下载一些数据(.png 和 .wav 文件) - 将下载每个文件的路径插入数据库(SQLite)
到目前为止一切顺利,一切正常。 有些用户问我是否有办法将下载的数据移动到 sd 卡中以节省一些内部空间。
现在我用这行代码创建目录
File directory = getApplicationContext().getDir("folderName", Context.MODE_PRIVATE);
然后该应用程序将用我下载的所有内容填充它。
我尝试使用这段代码:
try {
File newFolder = new File(Environment.getExternalStorageDirectory(), "TestFolder");
if (!newFolder.exists()) {
newFolder.mkdir();
}
try {
File file = new File(newFolder, "MyTest" + ".txt");
file.createNewFile();
System.out.println("Path: " + file.getPath());
} catch (Exception ex) {
System.out.println("ex: " + ex);
}
} catch (Exception e) {
System.out.println("e: " + e);
}
这会创建一个文件夹和一个文本文件到:/storage/emulated/0/TestFolder/MyTest.txt 这不是我的 sdcard 目录,它应该是: /storage/sdcard1/TestFolder/MyTest.txt
所以我的问题是: - 我将应用的私有数据(.png 和 .wav 文件)保存在 SD 卡中的位置和方式?
【问题讨论】: