Transform IO 【011】

package com.testiotransform_1;
import java.io.* ;
public class Test {
	/**
	 * 转换流OutputStreamWriter的测试
	 * 阻塞式(同步)方法
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try {
			OutputStreamWriter one = new OutputStreamWriter(new FileOutputStream("d:/java/test6.txt")) ;
			one.write("Enjoy java,enjoy everyday") ; //通过转换流可以直接写入字符串
			System.out.println(one.getEncoding()) ; //返回此流使用的字符编码的名称,中文windows系统默认使用 GBK码
			one.close();
			one = new OutputStreamWriter (new FileOutputStream("d:/java/test6.txt",true), "ISO8859_1") ;
			one.write("ONE WORLD ONE DREAM") ; //由于上行写了true,所以写在Enjoy java,enjoy life后边而不会擦除重写
			System.out.println(one.getEncoding()) ;
			one.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}


*********************************************************************
package com.testiotransform_1;
import java.io.* ;
public class Test1 {
	public static void main(String args[]) {
			InputStreamReader two = new InputStreamReader(System.in) ;
			BufferedReader three = new BufferedReader(two) ;
			String s = null ;
			try {
				System.out.println("Let's begin.Please input something !") ;
				s = three.readLine(); //读入输入的内容				
				while(s!=null) {
					if(s.equalsIgnoreCase("exit")) break ; //当输入exit 是退出
					System.out.println(s.toUpperCase()) ; //输出读入的内容,转换成大写
					System.out.println("Please input something:") ;
					s = three.readLine() ;  //继续读取
				}
				three.close() ;
			} catch (IOException e) {
				e.printStackTrace() ;
			}
	}

}

你可能感兴趣的:(java,windows)