有没有一种使用FileOutputStream的方式,如果文件(字符串文件名)不存在,那么它将创建该文件?
FileOutputStream oFile = new FileOutputStream("score.txt", false);
FileNotFoundException
如果该文件不存在且无法创建(doc),它将抛出一个,但是如果可以创建一个文件。为了确保您可能应该先测试文件是否存在,然后再创建FileOutputStream
(createNewFile()
如果不存在,请使用创建):
File yourFile = new File("score.txt");
yourFile.createNewFile(); // if file already exists will do nothing
FileOutputStream oFile = new FileOutputStream(yourFile, false);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句