Transform IO 【011】

[code]
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();
}
}
}

[/code]
*********************************************************************
[code]
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() ;
}
}

}
[/code]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值