Educoder -Java高级特性 - IO流( 第2关:字节流-输入输出)

package step2;
import java.io.File;
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 *********/
		File file = new File("src/step2/input/task.txt");
		FileInputStream in = new FileInputStream(file);
		byte[] bt = new byte[8];
		in.read(bt);
		String str = new String(bt,"UTF-8");
	    System.out.println(str);
	    
	    File file1 = new File("src/step2/output");
	    if(!file1.exists())
	    {
	    	file1.mkdir();
	    }
	    FileOutputStream out = new FileOutputStream("src/step2/output/output.txt");
	    String str1 = "learning practice";
	    byte[] bt1 = str1.getBytes();
	    out.write(bt1);
	    out.flush();
	    in.close();
	    out.close();
		
		/********* End *********/
	}
	
}

你可能感兴趣的:(Educoder -Java高级特性 - IO流( 第2关:字节流-输入输出))