JavaSE - Day21 (IO流及其文件上与下载)

IO流

作用

        程序与文件传输数据的通道

分类

        按照流向分类:

                输入流

                输出流

        按照最小传输单位分类:

                字节流
                字符流

        按照功能分类

                节点流

                过滤流

字节流

父类:

        InputStream (抽象类)

                read() 

                read(byte[] b)

                read(byte[] b , int off , int len)

                close() 关闭流

        OutputStream(抽象类)

                write()

                write(byte[] b)

                write(byte[] b , int off ,int len)

                flush()

                close()

      

常用子类

        文件流

                作用:读取文件中的内容 或者 给文件中写入内容

                FileInputStream

                FileOutputStream

                

public static void main(String[] args) throws IOException {
		FileInputStream fs = new FileInputStream("D:\\桌面\\Day06.txt");
		FileOutputStream fo = new FileOutputStream("D:\\缓冲流.txt" , true);
		
		BufferedInputStream bi = new BufferedInputStream(fs);
		BufferedOutputStream bo = new BufferedOutputStream(fo);
		
		byte[] b = new byte[1024];
		int len = 0;
		while ((len = bi.read()) != -1) {
			bi.read(b, 0, len);
			bo.write(b);
			bo.flush();
		}
		
		bo.close();
		bi.close();
		System.out.println("缓冲流测试成功,出现乱码问题");
	}

        内存流

                作用: 将数据读取到内存中 或者 从内存中取出数据

                ByteArrayInputStream

                ByteArrayOutputStream

                

	public static void main(String[] args) throws IOException {
		FileInputStream fi = new FileInputStream("D:\\桌面\\D
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值