我想输出文本到Java中的资源文件,像这样:如何查看Java中是否存在资源文件?
File file = new File(MLM.class.getClassLoader().getResource("mazes.txt").toString());
BufferedWriter out = new BufferedWriter(new FileWriter(file));
..
但由于资源文件尚未创建,我得到一个空指针异常。如何创建一个空白的资源文件,如果它不存在已经可以避免这个错误?
请检查这个帖子:http://stackoverflow.com/questions/1816673/how-do-i-check-if-a-file-exists-java-on-windows – adis 2012-02-21 16:00:45