【发布时间】:2013-12-20 14:38:16
【问题描述】:
我想在 sdcard 上创建一个文件。在这里我可以创建文件并将其读/写到应用程序,但我想要的是,文件应该保存在 sdcard 的特定文件夹中。如何使用FileOutputStream 做到这一点?
// create file
public void createfile(String name)
{
try
{
new FileOutputStream(filename, true).close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// write to file
public void appendToFile(String dataAppend, String nameOfFile) throws IOException
{
fosAppend = openFileOutput(nameOfFile, Context.MODE_APPEND);
fosAppend.write(dataAppend.getBytes());
fosAppend.write(System.getProperty("line.separator").getBytes());
fosAppend.flush();
fosAppend.close();
}
【问题讨论】:
-
查看文档。 developer.android.com/guide/topics/data/data-storage.html。您是否要存储在内部存储中?
-
是的,我想在内部存储中存储文件...
-
那么你的问题标题需要更改 将文件写入android的内部存储
-
对不起,mybad...我想存储在sdcard上...
标签: android file android-sdcard