写一个文件。JAVA安卓

写一个文件。JAVA安卓,java,android,file,Java,Android,File,在这段代码中,捕获IOException,但创建了文件。救命啊!谢谢大家的回答。试试这个: final String rootPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Slots/"; final File file = new File(rootPath); file.mkdirs(); final File sdFile = new File(file, "Profi

在这段代码中,捕获IOException,但创建了文件。救命啊!谢谢大家的回答。

试试这个:

 final String rootPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Slots/";
    final File file = new File(rootPath);
    file.mkdirs();
    final File sdFile = new File(file, "Profile.txt");
try {
    BufferedWriter bw = new BufferedWriter(new FileWriter(sdFile));
    bw.write(edit.getText().toString() + "\n");
    bw.write("5000");
    } catch (IOException e) {
}
确保在清单文件中添加此权限:

 final String rootPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Slots/";
 final File file = new File(rootPath);
 file.mkdirs();
 final File sdFile = new File(file, "Profile.txt");
try {
        FileWriter fw = new FileWriter(sdFile);
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write("hello "+"\n");
        bw.write("5000");
        bw.close();
    } catch (IOException e) {
        Log.e("exception ",e.getMessage());
    }

那么例外是怎么说的呢?文件中有什么?请解释更多,并尝试用代码示例写一个更清楚的问题
 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />