zoukankan      html  css  js  c++  java
  • IO流---字节流

    IO流  用来处理设备之间的数据传输

      分为 输入流    和  输出流

    按操作类型分为字符流  和 字节流

      字节流:   可以操作任意数据

      字符流 : 只能操作字符

    字节流抽象父类

          InputStream     OutputStream

       再往下的子类:   文件输入输出流    FileInputStream    FileOutputStream  

    //  输出流, 如果文件不存在会创建一个,   如果文件存在,需要续写的话,加一个参数    new FileOutputStream("bbb.txt",true);    true 代表追加 
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    
    public class demon1_FileInputStream {
    
        public static void main(String[] args) throws IOException  {
            //demo1();
            FileInputStream fl2 = new FileInputStream("xxx.txt");
            int b;
            while((b=fl2.read())!= -1){
                System.out.println(b);
            }
            fl2.close();
        }
    
        public static void demo1() throws FileNotFoundException, IOException {
            FileInputStream fl1 = new FileInputStream("xxx.txt");
            int x = fl1.read();    // 读取一个字节         ASK码表    GBK
            System.out.println(x);
            int y = fl1.read();
            System.out.println(y);
            fl1.close();//关流  释放资源
        }
    
    }
    public class demon2_OutputStream {
      //  输出流, 如果文件不存在会创建一个,   如果文件存在,需要续写的话,加一个参数    new FileOutputStream("bbb.txt",true);    true 代表追加 
        public static void main(String[] args) throws IOException {
            FileOutputStream fo1 = new FileOutputStream("yyy.txt");
            /*fo1.write(97);
            fo1.write(98);
            fo1.write(99);*/
            fo1.write(100);
            
            fo1.close();
            
        }
    竹杖芒鞋轻胜马,一蓑烟雨任平生。 回首向来萧瑟处,也无风雨也无晴。
  • 相关阅读:
    Find the Smallest K Elements in an Array
    Count of Smaller Number
    Number of Inversion Couple
    Delete False Elements
    Sort Array
    Tree Diameter
    Segment Tree Implementation
    Java Programming Mock Tests
    zz Morris Traversal方法遍历二叉树(非递归,不用栈,O(1)空间)
    Algorithm about SubArrays & SubStrings
  • 原文地址:https://www.cnblogs.com/yaobiluo/p/11312299.html
Copyright © 2011-2022 走看看