【发布时间】:2015-01-22 20:18:28
【问题描述】:
大家好,我是 java 和 android 世界的大佬。 这是我第一次在 stackoverflow.com 上寻求帮助
我正在尝试在我的第一个应用程序 android 中创建文件文本。
这是一个示例代码
String string = nome;
try {
File file = new File("prova.txt");
FileOutputStream fos =null;
if (file.exists() ) {
fos = new FileOutputStream("prova.txt", true);
PrintWriter print = new PrintWriter(fos);
print.append(nome);
print.close();
} else if (file.createNewFile()) {
PrintWriter print = new PrintWriter(file);
print.println(nome);
print.close();
}
}
catch (Exception e)
{
e.printStackTrace();
}
应用程序不会创建文件。 你能帮帮我吗? 你能解释一下为什么吗?
非常感谢
【问题讨论】:
-
看看这个答案它应该可以工作并且评论很好:stackoverflow.com/a/7718374/1173391
-
还要确保添加允许您访问外部存储的权限:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />