Java 写文件2 Java 写文件1 Java 递归创建目录(多层目录) Java 写文件2 import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; public class FileExample { public static void main(String[] args) { try { String content = "codingdict is one the best site in the world"; File file = new File("C:\\Users\\codingdict7\\Desktop\\abc.txt"); if (!file.exists()) { file.createNewFile(); } FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(content); bw.close(); System.out.println("Done"); } catch (IOException e) { e.printStackTrace(); } } } Java 写文件1 Java 递归创建目录(多层目录)