本文共 875 字,大约阅读时间需要 2 分钟。
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(); }}
转载地址:http://llrqj.baihongyu.com/