我想写一些关于用户重用它们的信息,但我不能创建一个文本文件,所以我也无法阅读它。在开始阅读之前,我想完成写入文本文件。
我将用户权限写入清单文件。
另外,我的代码用于写入文本文件,如下所示:
public static void writeFile(String item, String fileName) throws IOException {
BufferedWriter out;
try {
FileWriter fileWriter= new FileWriter(Environment.getExternalStorageDirectory().getPath()+"/"+fileName);
out = new BufferedWriter(fileWriter);
out.write(item);
out.close();
}catch (FileNotFoundException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}
}
所以有人能说出这个问题吗?谢谢。
答案 0 :(得分:0)
据我所知,你可能想要使用共享偏好,看看:Simple Example Sharedpreferences
您可以轻松存储和检索数据......
总之...
确保您的清单包含: 1. android:name =“android.permission.READ_EXTERNAL_STORAGE 2. android:name =“android.permission.WRITE_EXTERNAL_STORAGE
String string1 = "Hey you";
FileOutputStream fos ;
try {
fos = new FileOutputStream("/sdcard/filename.txt", true);
FileWriter fWriter;
try {
fWriter = new FileWriter(fos.getFD());
fWriter.write("hi");
fWriter.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
fos.getFD().sync();
fos.close();
}
} catch (Exception e) {
e.printStackTrace();
}