• [Java] IO-03 TransForm1 / TransForm2


    import java.io.*;
    
    public class TestTransForm1 {
        public static void main(String[] args) {
            try {
                OutputStreamWriter osw = new OutputStreamWriter(
                        new FileOutputStream("d:\bak\char.txt"));
                osw.write("mircosoftibmsunapplehp");
                System.out.println(osw.getEncoding());
                osw.close();
                osw = new OutputStreamWriter(new FileOutputStream(
                        "d:\bak\char.txt", true), "ISO8859_1"); // latin-1
                osw.write("mircosoftibmsunapplehp");
                System.out.println(osw.getEncoding());
                osw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    
    import java.io.*;
    
    public class TestTransForm2 {
        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();
            }
        }
    } // 阻塞
    
    import java.io.*;
    public class TestDataStream {
      public static void main(String[] args) {
        ByteArrayOutputStream baos = 
                            new ByteArrayOutputStream(); 
        DataOutputStream dos = 
                            new DataOutputStream(baos);
        try {
          dos.writeDouble(Math.random());
          dos.writeBoolean(true);
          ByteArrayInputStream bais = 
              new ByteArrayInputStream(baos.toByteArray());
          System.out.println(bais.available());
          DataInputStream dis = new DataInputStream(bais);
          System.out.println(dis.readDouble());
          System.out.println(dis.readBoolean());
          dos.close();  dis.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
    



  • 相关阅读:
    Linux 终端常用快捷键
    问题集
    数据库
    mysql数据库知识点
    IntelliJ IDEAj集成开发环境
    Windows最全DOS的CMD命令
    DB2移植到Oracle数据库完整的图解教程
    169.254是什么IP地址 169.254的解决方法(添加局域网地址时)
    解析xml时报错
    童年乐趣
  • 原文地址:https://www.cnblogs.com/robbychan/p/3786899.html
Copyright © 2020-2023  润新知