灯火互联
管理员
管理员
  • 注册日期2011-07-27
  • 发帖数41778
  • QQ
  • 火币41290枚
  • 粉丝1086
  • 关注100
  • 终身成就奖
  • 最爱沙发
  • 忠实会员
  • 灌水天才奖
  • 贴图大师奖
  • 原创先锋奖
  • 特殊贡献奖
  • 宣传大使奖
  • 优秀斑竹奖
  • 社区明星
阅读:3018回复:0

java例程练习(转换流)

楼主#
更多 发布于:2012-09-08 09:43

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



喜欢0 评分0
游客

返回顶部