java例程练习(转换流)

import java.io.*;

public class Test {
	public static void main(String[] args) {
		try {
			OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("C:/java/char.txt"));
			osw.write("microsoftibssunapplehp");
			System.out.println(osw.getEncoding());//文本编码
			osw.close();
			
			//加了true 可以再文件末尾添加
			osw = new OutputStreamWriter(new FileOutputStream("C:/java/char.txt", true),"ISO8859_1");
			osw.write("microsoftibssunapplehp");
			System.out.println(osw.getEncoding());//文本编码
			osw.close();
		} catch (IOException e) {
		}
	}
}

import java.io.*;
public class Test {

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


原文地址:https://www.cnblogs.com/wjchang/p/3671700.html