File myFile = new File(fileName); //判断文件是否存在,如果不存在则调用createNewFile()方法创建新目录,否则跳至异常处理代码 if(!myFile.exists()) myFile.createNewFile(); else //如果不存在则扔出异常 throw new Exception("The new file already exists!");