[英]Writing file to internal storage
我想在Android內部存儲中寫入或放置文件,而我正在這樣做-
try {
File file = new File("/data/local/measurement.txt");
// if file doesnt exists, then create it
if (!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(content.toString());
bw.close();
Log.d("hi", "WRITTEN");
} catch (IOException e) {
e.printStackTrace();
}
我已經在/ data / local路徑中具有Measurement.txt,但是沒有寫入任何內容。 我正在使用模擬器,並且還授予了以下權限
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(context.openFileOutput("myfile", MODE_PRIVATE)));
out.write(string);
out.close();
這會將文件放在應用所屬的/data/data/<pkg>/files
,該/data/data/<pkg>/files
專用於您的應用。 您不需要任何權限。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.