io字节流

io流概述

io流概述

一切皆为字节

一切皆为字节

outputstream与Fileoutputstream介绍

outputstream与Fileoutputstream介绍

原理

原理
  FileOutputStream fileOutputStream = new FileOutputStream("f:\\电影\\111\\a.txt");
        fileOutputStream.write(72);
        fileOutputStream.close();

文件存储原理以及文件打开原理

文件存储原理以及文件打开原理

字节输出流写多个字节的方法

  public static void main(String[] args) throws IOException {
        FileOutputStream fileOutputStream = new FileOutputStream("f:\\电影\\111\\a.txt");
        //第一种
        fileOutputStream.write(72);
        fileOutputStream.write(73);
        fileOutputStream.write(74);
        //第二种
        byte[] bytes={49,50,51};
        fileOutputStream.write(bytes);
        //第三种
        fileOutputStream.write(bytes,1,1);
        //第四种
        byte[] bytes1 = "把字符串转为字节数组写入".getBytes();
        fileOutputStream.write(bytes1);
        fileOutputStream.close();

    }

字节输出流的续写和换行

字节输出流的续写和换行
package com.mujiachao.io;

import java.io.FileOutputStream;
import java.io.IOException;

public class OutPut2 {
    public static void main(String[] args) throws IOException {
        FileOutputStream fileOutputStream = new FileOutputStream("f:\\电影\\111\\a.txt",true);
        byte[] bytes = "续写".getBytes();
        fileOutputStream.write(bytes);
        for (int i = 0; i < 10; i++) {
            fileOutputStream.write("\r\n".getBytes());
            fileOutputStream.write("换行".getBytes());
        }
        fileOutputStream.close();

    }
}

InputStream与FileInputStream介绍

InputStream与FileInputStream介绍

字节输入流读取字节数据

字节输入流读取字节数据
package com.mujiachao.io;

import java.io.FileInputStream;
import java.io.IOException;

public class InPut {
    public static void main(String[] args) throws IOException {
        FileInputStream fileInputStream = new FileInputStream("f:\\电影\\111\\a.txt");
                int len=0;
                while ((len=fileInputStream.read())!=-1){
                    System.out.println((char) len);
                }
                 fileInputStream.close();

    }
}

读取数据的原理

读取数据的原理

字节输入流一次读取多个字节

字节输入流一次读取多个字节
package com.mujiachao.io;

import java.io.FileOutputStream;
import java.io.IOException;

public class OutPut2 {
    public static void main(String[] args) throws IOException {
        FileOutputStream fileOutputStream = new FileOutputStream("f:\\电影\\111\\a.txt",true);
        byte[] bytes = "续写".getBytes();
        fileOutputStream.write(bytes);
        for (int i = 0; i < 10; i++) {
            fileOutputStream.write("\r\n".getBytes());
            fileOutputStream.write("换行".getBytes());
        }
        fileOutputStream.close();

    }
}

你可能感兴趣的:(io字节流)