在当前路径新建文本文档.java import java.io.*;import java.util.logging.Level;import java.util.logging.Logger;public class createEmptyFiles { public static void main(String[] args) { String fileName = "新建文本文档.txt"; File
import java.io.*; import java.util.logging.Level; import java.util.logging.Logger; public class createEmptyFiles { public static void main(String[] args) { String fileName = "新建文本文档.txt"; File file = new File(fileName); int counter = 2; while(file.exists()){ fileName = "新建文本文档" + "(" + counter + ")" + ".txt"; file = new File(fileName); counter++; } try { file.createNewFile(); System.out.println("创建成功"); } catch (IOException ex) { Logger.getLogger(createEmptyFiles.class.getName()).log(Level.SEVERE, null, ex); } } }