我尝试使用下面显示的代码创建一个文本文件并向其中写入数据:
JAVA CODE_1:
File dir = Environment.getExternalStorageDirectory();
File file = new File(dir,"/DCIM/"+fileTitle);
try {
if( file.exists() ){
FileOutputStream fos = openFileOutput(fileTitle, MODE_WORLD_READABLE);
OutputStreamWriter osw = new OutputStreamWriter(fos);
osw.write("this is a text");
osw.flush();
osw.close();
} else {
file.createNewFile();
FileOutputStream fos = openFileOutput(fileTitle, MODE_WORLD_READABLE);
OutputStreamWriter osw = new OutputStreamWriter(fos);
osw.write("this is a text");
osw.flush();
osw.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
但是当我检查 DCIM 目录时,我发现文件已创建但没有数据写入其中。请告诉我我的错误在哪里。