码迷,mamicode.com
首页 > 其他好文 > 详细

IO流---字节流

时间:2019-08-06 22:42:39      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:nbsp   not   otf   span   字节   write   main   资源   stat   

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

 

IO流---字节流

标签:nbsp   not   otf   span   字节   write   main   资源   stat   

原文地址:https://www.cnblogs.com/yaobiluo/p/11312299.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!