【发布时间】:2011-12-17 14:00:47
【问题描述】:
如果我在 ASUS Transformer 上运行以下代码,则会按预期在“sd 卡”目录的顶层创建“testfile.txt”。
private void testWriteFile () throws IOException
{
File sdCard = Environment.getExternalStorageDirectory();
File file = new File(sdCard, "testfile.txt");
FileOutputStream myOutput = new FileOutputStream(file);
byte buffer[] = {'0','1','2','3','4','5','6','7','8','9'};
myOutput.write(buffer,0,buffer.length);
myOutput.flush();
myOutput.close();
}
我可以使用文件管理器应用程序查看 ASUS Transformer 上的文件。我可以通过“adb shell”命令从 Windows DOS 框中看到该文件,并且它的权限似乎设置正确。但是,如果我从 Windows 资源管理器中查看目录,则不存在“testfile.txt”。我已经设置了显示隐藏文件和系统文件的选项,但没有成功。
如果我使用 ASUS 文件管理器应用程序更改“testfile.txt”的名称,则它会在 Windows 资源管理器中可见,因此其他应用程序能够使文件在资源管理器中可见。
如果我在 ZTE Blade(Orange San Francisco)上运行相同的代码,那么我可以在 Windows 资源管理器中看到“testfile.txt”,而无需更改其名称。
我还需要做些什么来完成此文件以使其可见吗?
这里报告了类似的问题,Can't see a file in Windows written by an android app on sd-card unless I "Force Close" the app,但在我的情况下强制关闭不会使文件可见。
【问题讨论】:
标签: android windows-7 android-sdcard