我想輸出文本到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