创建a. txt的File类对象,如果文件存在改名字为b. txt, 如果不存在则创建a. txt
收起
示例代码如下:
public class Main { public static void main(String[] args) throws IOException { File file = new File("a.txt"); if (file.exists()) { file.renameTo(new File("b.txt")); } else { file.createNewFile(); } } }
如有帮助,请采纳。
报告相同问题?