テキストファイルを作成してテキストを挿入しようとしています。 私はマニフェストの権限を追加しました:ファイルを作成し、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)