Advertisement
wyx0311

java实验六

Apr 15th, 2025
295
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | Source Code | 0 0
  1. package org.example;
  2. import java.io.*;
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.     public static void main(String[] args) throws IOException {
  7.         String source_filename = "D://Hello.txt";
  8.         String target_filename = "D://Hello.txt";
  9.  
  10.         System.out.println("请输入源文件地址 ");
  11.         source_filename = ( new Scanner(System.in)).nextLine();
  12.         System.out.println("请输入目标文件地址 ");
  13.         target_filename = ( new Scanner(System.in)).nextLine();
  14.  
  15.  
  16.         FileReader fr = new FileReader(source_filename);
  17.         BufferedReader br = new BufferedReader(fr);
  18.  
  19.         FileWriter fw = new FileWriter(target_filename, true);
  20.         BufferedWriter bw = new BufferedWriter(fw);
  21.  
  22.  
  23.  
  24.  
  25.         String line;
  26.         while((line = br.readLine())!=null){
  27.             bw.write(line);
  28.             bw.newLine();
  29.             System.out.println(line);
  30.         }
  31.  
  32.         bw.flush();
  33.  
  34.         br.close();
  35.         fr.close();
  36.         bw.close();
  37.         fw.close();
  38.     }
  39. }
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement