首页 > 其他分享 >利用 BufferedReader 和 BufferedWriter 完成文本文件的复制

利用 BufferedReader 和 BufferedWriter 完成文本文件的复制

时间:2023-02-28 15:00:59浏览次数:34  
标签:java 文本文件 BufferedReader BufferedWriter io new import

package 课后作业;

/*
 利用 BufferedReader 和 BufferedWriter 完成文本文件的复制
 */

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class test2 {
	public static void main(String[] args) throws IOException {
		File file = new File("H:\\temp\\text.txt");
		FileReader fileReader = new FileReader(file);
		BufferedReader bufferedReader = new BufferedReader(fileReader);
        FileWriter fileWriter=new FileWriter("H:\\temp2\\text.txt");
        BufferedWriter bufferedWriter=new BufferedWriter(fileWriter);
        String str ;
        while (((str=bufferedReader.readLine())!=null)){
        	 
        	 bufferedWriter.write(str);
        }
         bufferedWriter.flush();
         bufferedReader.close();
       bufferedWriter.close();
        
		
		
		
	}
}

标签:java,文本文件,BufferedReader,BufferedWriter,io,new,import
From: https://blog.51cto.com/u_11343833/6091160

相关文章