我試圖創建一個文本文件並插入文本。 我添加的權限清單:創建一個文件並在android中插入文本
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
但是當我試圖打開一個文件,並插入測試:
int permission = ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permission != PackageManager.PERMISSION_GRANTED) {
// We don't have permission so prompt the user
}
File file = new File(Environment.getExternalStorageDirectory(), "myfile.txt");
try {
FileOutputStream stream = new FileOutputStream(file);
stream.write("test".getBytes());
stream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
// FragmentTools.alertbox(getActivity(), "erreur d'écriture");;
}
我有這些錯誤:
java.io.FileNotFoundException: /storage/1B0C-330F/monfichier.txt: open failed: EACCES (Permission denied)