2016-06-28 25 views
1

我想使用以下代碼將數據保存在輸出文件中。但是我不知道在應用程序執行後我在哪裏找到這個文件。我在哪裏找到由android應用程序修改的文件

 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()); 
} 

謝謝你的回答。

回答

1

此文件存儲在您的應用程序數據中。您無法從「文件管理器」查看此文件,直到您的手機爲根。 因此,如果您提供外部目錄路徑會更好:

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()); 
} 
+0

謝謝你的回答。所以我不能簡單地將文件保存在內部存儲器中? – fao

+0

是的,你可以保存它。但請告訴我你想要保存文件的位置。我給你這個答案將文件保存在手機內存的內部存儲器中。不在應用程序存儲中。 –

1

此文件存儲在您的內部存儲器中。您將無法從外部查看此文件。 如果您想要在外部查看外部SD卡,請爲其指定路徑

相關問題