import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; public class filedemo{ public static void main(String[] args) throws IOException{ String str = "12345abcdef@#&*软件工程"; File file = new File("data.txt"); FileWriter fw = new FileWriter(file); BufferedWriter bw = new BufferedWriter(fw); bw.write("12345abcdef@#&*软件工程"); bw.newLine(); bw.write("请多指教。"); bw.close(); fw.close(); } } import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; public class readfile { public static void main(String[] args) throws IOException { File file=new File("data.txt"); FileReader fr = new FileReader(file); BufferedReader br=new BufferedReader(fr); String str; while ((str = br.readLine()) != null) { System.out.println(str); } System.out.println("绝对路径:" + file.getAbsolutePath()); br.close(); fr.close(); } }