我正在尝试在我的Android应用程序中将文件写入内部存储器,但是,虽然调用了此代码,但稍后当我尝试读取该文件时,应用程序崩溃并出现fileNotFound异常。我正在尝试编写一个数组,每个引用都在一个新行上。
try{
File myOutputFile = new File ("data/data/com.example.referencetool/files", filename );
FileWriter fw = new FileWriter(myOutputFile, true);
BufferedWriter bw = new BufferedWriter(fw);
if(isFirstTime){
myOutputFile.createNewFile();
}
int i = 0;
while(i<=toSave.length){
if(toSave[i].equals(null)){
bw.write("null");
}
else{
bw.write(toSave[i]);
}
bw.newLine();
i++;
}
bw.flush();
bw.close();
}
catch(Exception e){
e.printStackTrace();
}
谢谢!
答案 0 :(得分:0)
您可以Read/ Write
中的data/data/package_name/files Folder
{/ 1}}文件,
BufferedReader bufferedReader = new BufferedReader(new FileReader(new
File(getFilesDir()+File.separator+"MyFile.txt")));
String read;
StringBuilder builder = new StringBuilder("");
while((read = bufferedReader.readLine()) != null){
builder.append(read);
}
Log.d("Output", builder.toString());
bufferedReader.close();