goback add

java例程练习(转换流)

3761 点击·0 回帖
灯火互联
楼主

[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