IO流读取文件
import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.FileReader;import java.io.FileWriter;import java.io.InputStreamReader;import java.io.OutputStream;import java.io.OutputStreamWriter;public class FileOperate {public static void main(String[] args) throws Exception {readAndWriteBy();readAndWrite();}//读取文件,再写入文件public static void readAndWriteBy() throws Exception{//一种FileInputStream f = new FileInputStream("d:/1.txt");InputStreamReader isr = new InputStreamReader(f,"GBK");BufferedReader br = new BufferedReader(isr);OutputStream fop = new FileOutputStream("d:/2.txt");OutputStreamWriter osr = new OutputStreamWriter(fop,"GBK");BufferedWriter bw = new BufferedWriter(osr);String line="" ;while((line=br.readLine())!=null){bw.write(line);}bw.flush();bw.close();br.close();}public static void readAndWrite() throws Exception{//二种File file = new File("d:/1.txt");BufferedReader br = new BufferedReader(new FileReader(file));BufferedWriter bw = new BufferedWriter(new FileWriter("d:/3.txt"));String line="" ;while((line=br.readLine())!=null){bw.write(line);}bw.flush();bw.close();br.close();}}