Tramsform IO

package com.bjsxt.transform;

import java.io.FileOutputStream;
import java.io.OutputStreamWriter;

public class TestTransform1 {

	public static void main(String[] args) throws Exception {
		OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("c:\\bak\\char.txt"));
		osw.write("microsoftibmsunapplehp");
		System.out.println(osw.getEncoding());
		osw.close();
		osw = new OutputStreamWriter(new FileOutputStream("c:\\bak\\char.txt",true),"ISO8859_1");
		osw.write(" microsoftibmsunapplehp");
		System.out.println(osw.getEncoding());
		osw.close();
	}
	
}
转换流:从OutputStreamWriter可知识OutputStream往Writer转换


package com.bjsxt.transform;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class TestTransform2 {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		String s = null;
		s  = br.readLine();
		while(s != null) {
			if(s.equalsIgnoreCase("exit")) {
				break;
			}
			System.out.println(s.toUpperCase());
			s = br.readLine();
		}
		br.close();
	}

}

你可能感兴趣的:(转换流)