字符輸入輸出流的簡單使用

//1 給出數據源 2 給出流 3 再就是使用 public class Object_test {code

public static void main(String[] args)throws Exception {

    InputStream f=new FileInputStream(new File("d:/test/a.txt"));
	
    InputStreamReader in = new InputStreamReader(f,"utf-8");
	
    char c[]=new char[10];
	
    int len=-1;

// // while ((len=in.read(c))!=-1){utf-8

// String s=new String(c,0,len);it

// System.out.print(s);io

// }class

OutputStream out = new FileOutputStream(new File("d:/test/copy.txt"));
	
    OutputStreamWriter writer=new OutputStreamWriter(out);
	

    int len1=-1;
	
    while ((len1=in.read(c))!=-1){
	
        writer.write(c,0,len1);
		
    }
	
    //記住關閉的順序
    in.close();
    writer.close();
    f.close();
    out.close();
}

}test

相關文章
相關標籤/搜索