我正在创建File
。它适用于除Pie版本之外的所有版本。这是我的代码。
private void writeToFile(String data, Context context) {
try {
File file = new File(Environment.getExternalStorageDirectory() + File.separator + "testApp.txt");
if (!file.exists()) {
file.createNewFile();
}
FileWriter writer = new FileWriter(file);
writer.append(data);
writer.flush();
writer.close();
} catch (IOException e) {
Log.e("Exception", "File write failed: " + e.toString());
}
}