【发布时间】:2016-08-15 08:51:17
【问题描述】:
String fileName = "sample";
try {
final File f= new File(Environment.getExternalStorageDirectory(), fileName);
FileOutputStream fo = new FileOutputStream(f);
fo.write(code.getBytes());
fo.close();
Toast.makeText(getBaseContext(),"Done writing SD 'mysdfile.txt'",
Toast.LENGTH_SHORT).show();
} catch (FileNotFoundException e) {
Toast.makeText(getBaseContext(), e.getMessage(),
Toast.LENGTH_SHORT).show();
} catch (IOException e) {
Toast.makeText(getBaseContext(), e.getMessage(),
Toast.LENGTH_SHORT).show();
}
我需要将名为 code 的字符串复制到名为 sample 的文件中。
如果我这样做,我不会收到任何错误。但是,如果使用我的手机并调试到我的 SD 卡,则不会创建文件。谁能告诉我我做错了什么??
【问题讨论】:
-
if use my connected android phone as emulator。 ???如何做到这一点? -
and look into my sdcard , no file is created。确实。它不是在 micro SD 卡上创建的,而是在手机的外部存储器上创建的。 -
I dont get any errors.你应该干杯!哪一个? -
String fileName = "sample";和"Done writing SD 'mysdfile.txt'"。您可以通过不对其进行硬编码而是使用file.getName()或file.getAbsolutePath()来防止此类令人困惑的消息。有了最后一个,您就知道必须准确查看的位置。 -
错了。在您的设备上使用文件资源管理器应用。
标签: android file android-studio android-sdcard