import java.io.*; import java.util.Scanner; public class Test_8_2 { public static void main(String[] args) throws IOException { String str = "src/allTest/Test_8_2File_1"; String strs = "src/allTest/Test_8_2File_2"; File fi = new File(str); File fis = new File(strs); Scanner sc = new Scanner(System.in); BufferedReader br = new BufferedReader(new FileReader(fi)); String l; System.out.println("Test_8_2File_1文件数据:"); while((l = br.readLine())!= null){ System.out.println(l); } System.out.println("请修改您的数据:"); String strplus = sc.next(); System.out.println("正在写入您的数据到Test_8_2File_2文件~"); System.out.println("写入成功,正在读取Test_8_2File_2的数据:"); BufferedWriter brs = new BufferedWriter(new FileWriter(fis)); brs.write(strplus); brs.flush(); brs.close(); BufferedReader brr = new BufferedReader(new FileReader(strs)); String line; while((line = brr.readLine()) != null){ System.out.println(line); } System.out.println("读取成功~操作结束~"); brr.close(); } }