Educoder -Java高级特性 - IO流(第4关:复制文件)

package step4;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class Task {
	
	public void task() throws IOException{
		/********* Begin *********/
		FileReader fr = new FileReader("src/step4/input/input.txt");
		FileWriter fw = new FileWriter("src/step4/output/output.txt");
		int len = 0;
		char[] cha = new char[1024];
		while ( (len = fr.read(cha) ) != -1) 
		{
			fw.write(cha , 0 , len);
		}
		fr.close();
		fw.flush();
		fw.close();
		
		FileInputStream fs = new FileInputStream("src/step4/input/input.jpg");
		FileOutputStream fo = new FileOutputStream("src/step4/output/output.jpg");
		int le = 0;
		byte[] bt = new byte[1024];
		while ( (le = fs.read(bt) ) != -1)
		{
			fo.write (bt , 0 , le);
		}
		fs.close();
		fo.flush();
		fo.close();		
		/********* End *********/		
	}
}

你可能感兴趣的:(Educoder -Java高级特性 - IO流(第4关:复制文件))