在那里我找到了被android应用程序修改的文件
我想使用以下代码将数据保存在输出文件中。但是我不知道在应用程序执行后在哪里找到这个文件在那里我找到了被android应用程序修改的文件,android,file,Android,File,我想使用以下代码将数据保存在输出文件中。但是我不知道在应用程序执行后在哪里找到这个文件 try { // open myfilename.txt for writing OutputStreamWriter out = new OutputStreamWriter(openFileOutput("myfile.txt", Context.MODE_PRIVATE)); // write the contents on mySettings to the file out.wri
try {
// open myfilename.txt for writing
OutputStreamWriter out = new OutputStreamWriter(openFileOutput("myfile.txt", Context.MODE_PRIVATE));
// write the contents on mySettings to the file
out.write("x="+Float.toString(xx)+" y="+Float.toString(yy)+" z="+Float.toString((zz))+" Puissance="+Float.toString(magneticStrenght));
// close the file
out.close();
} catch (java.io.IOException e) {
//do something if an IOException occurs.
Log.e("Exception", "File write failed: " + e.toString());
}
谢谢你的回答 此文件存储在您的内部存储器中。您将无法从外部查看此文件。
如果要在外部查看文件存储的外部sd卡,请提供其路径。此文件存储在应用程序数据中。只有在手机根目录下才能从文件管理器查看此文件。 因此,如果您提供以下外部目录路径会更好:
File openfilename= new File(Environment.getExternalStorageDirectory(),"myfile.txt");
try {
// open myfilename.txt for writing
FileOutputStream f = new FileOutputStream(file);
// write the contents on mySettings to the file
PrintWriter pw = new PrintWriter(f);
pw.println(("x="+Float.toString(xx)
+" y="+Float.toString(yy)
+" z="+Float.toString((zz))+" Puissance="
+Float.toString(magneticStrenght));
// close the file
pw.flush();
pw.close();
f.close();
} catch (java.io.IOException e) {
//do something if an IOException occurs.
Log.e("Exception", "File write failed: " + e.toString());
}
谢谢你的回答。所以我不能简单地将文件保存在内存中?是的,你可以保存它。但是告诉我你想把文件保存在哪里。我已经给你这个答案,以保存在手机内存的内部存储文件。不在应用程序存储中。