麻烦帮忙看一下这段代码,为什么file.createNewFile()可以省略?

//---SD Card Storage---
File sdCard = Environment.getExternalStorageDirectory();
File directory = new File (sdCard.getAbsolutePath() +
“/MyFiles”);
directory.mkdirs();
File file = new File(directory, “textfile.txt”);
FileOutputStream fOut = new FileOutputStream(file);

OutputStreamWriter osw = new
OutputStreamWriter(fOut);
//---write the string to the file---
osw.write(str);
osw.flush();
osw.close();

白板的微信
浏览 175回答 2
2回答

人到中年有点甜

sdCard = Environment.getExternalStorageDirectory(); File directory = new File (sdCard.getAbsolutePath() + “/MyFiles”); directory.mkdirs(); File file = new File(dire

慕后森

因为那个文件存在
打开App,查看更多内容
随时随地看视频慕课网APP