자바 IO 변환 흐름 의 인 코딩 디 코딩

2037 단어 자바 학습
package io.transstream.demo;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;

import javax.print.attribute.standard.OutputDeviceAssigned;

import com.sun.org.apache.xml.internal.serialize.OutputFormat;

public class TransStreamDemo3 {

	public static void main(String[] args) throws IOException {
		readText_2();
	}



	private static void readText_2() throws IOException {
		InputStreamReader isr=new InputStreamReader(new FileInputStream("gbk.txt"),"UtF-8");
		char []buf=new char[10];
		int len=isr.read(buf);
		String str=new String(buf, 0, len);
				System.out.println(str);
				isr.close();
	}



	private static void readText_1() throws IOException {
		FileReader fr=new FileReader("u8_1.txt");
		char []buf=new char[10];
		int len=fr.read(buf);
		String str=new String(buf, 0, len);
				System.out.println(str);
				fr.close();
	}



	private static void writeText_3() throws IOException {
		OutputStreamWriter osw=new OutputStreamWriter(new FileOutputStream("u8_1.txt"),"utf-8");
		osw.write("  ");
		osw.close();
	}
	



	private static void writeText_2() throws IOException {
		OutputStreamWriter osw=new OutputStreamWriter(new FileOutputStream("gbk_2.txt"));
		OutputStreamWriter osw2=new OutputStreamWriter(new FileOutputStream("gbk_2.txt"),"gbk");
		/*
		 *             
		 * FileWriter:                                           
		 *			   :        +        
		 *			                 
		 *                   FileWriter            
		 *
		 */
		osw.write("  ");
		osw.close();
	}



	private static void writeText_1() throws IOException {
		FileWriter fw=new FileWriter("gbk.txt");
		
		fw.write("  ");
		fw.close();
	}

}

좋은 웹페이지 즐겨찾기