------- android培训、java培训、期待与您交流! ----------
切割流和合并流:
切割流:一个源流对应多目的流 指定大小输出到不同的流中
合并流:多个源流对应一个目的流 先把源流合并起来,再输出到目的流 SequenceInputStream

import java.io.*;
import java.util.*;
class SplitAndSequence
{static int count = 0;public static void main(String[] args) throws IOException{splitFile();sequence();}public static void sequence()throws IOException{ArrayList<FileInputStream> al = new ArrayList<FileInputStream>();for (int x=1; x<=count; x++){al.add(new FileInputStream("part\\"+x+".part"));}final Iterator<FileInputStream> it = al.iterator();Enumeration<FileInputStream> en = new Enumeration<FileInputStream>(){public boolean hasMoreElements(){return it.hasNext();}public FileInputStream nextElement(){return it.next();}};SequenceInputStream sis = new SequenceInputStream(en);//合并输入流,参数是一个枚举对象。FileOutputStream fos = new FileOutputStream("part\\tanfu.mp3");byte[] buf = new byte[1024];int len = 0;while((len=sis.read(buf))!=-1){fos.write(buf,0,len);}fos.close();sis.close();}public static void splitFile()throws IOException{FileInputStream fis = new FileInputStream("tanfu.mp3");FileOutputStream fos = null;byte[] buf = new byte[1024*1024];int len =0;//int count =1;while((len=fis.read(buf))!=-1){fos = new FileOutputStream("part\\"+(++count)+".part");fos.write(buf,0,len);fos.close();}fis.close();}}

对象的序列化:对象的持久化。需要对象的类实现 Serializable接口,并且定义固定的
UID:public static final long serialVersionUID = 42L;
对象中的成员(成员变量和成员函数)都是计算UID的部分,如果改变成员的值,会生成新的
UID,不能再用流读取硬盘上的对象。如果需要让指定成员不被序列化,可以用关键字 transient
修饰。
注意:静态是不能序列化的。

import java.io.*;
class  ObjectStreamDemo
{public static void main(String[] args) throws Exception{//writeObj();readObj();}public static void readObj()throws Exception{ObjectInputStream ois = new ObjectInputStream(new FileInputStream("obj.txt"));Person p  = (Person)ois.readObject();System.out.println(p);ois.close();}public static void writeObj()throws IOException{ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("obj.txt"));oos.writeObject(new Person("lisi",40));oos.close();}
}
class Person implements Serializable
{public static final long serialVersionUID = 42L;String name;int age;Person(String name,int age){this.name = name;this.age = age;}public String toString(){return name+".."+age;}
}

管道流: PipedInputStream  PipedOutputStream 与多线程相关

import java.io.*;
class Read implements Runnable
{private PipedInputStream in;Read(PipedInputStream in){this.in = in;}public void run(){try{byte[] buf = new byte[1024];int len = in.read(buf);String s = new String(buf,0,len);System.out.println(s);in.close();}catch (IOException e){throw new RuntimeException("管道读取失败");}}
}
class Write implements Runnable
{private PipedOutputStream out;Write(PipedOutputStream out){this.out = out;}public void run(){try{out.write("piped is coming".getBytes());out.close();}catch (IOException e){throw new RuntimeException("管道读取失败");}}
}
class  PipedStreamDemo
{public static void main(String[] args) throws IOException{PipedInputStream in = new PipedInputStream();PipedOutputStream out = new PipedOutputStream();in.connect(out);new Thread(new Read(in)).start();new Thread(new Write(out)).start();}
}

RandomAccessFile:该类直接继承自Object,但是是IO包中的成员,因为具备读和写的功能。
内部封装了一个数组,通过指针对数组的元素进行操作。可以通过getFilePointer获取指针位置,
同时可以通过seek改变指针的位置。能完成读写的原理是内部封装了读取流和写入流。
构造函数中只能接受文件,并且有指定操作模式。只读:"r" ,读写:"rw".
如果模式为只读,不会创建文件,如果该文件不存在,则会发生异常
如果模式为读写,如果该对象的构造函数要操作的文件不存在,会自动创建。如果存在则不覆盖。
可以通过设置指针偏移随机访问数组中的元素。
seek(int offset): 调整对象的指针,按照指针位置读取写入,如果指针位置已有内容,写入内容会覆盖原来内容。
skipBytes(int number):跳过指定字节数

DataInputStream DataOutputStream:基本数据类型流对象
可以对基本数据类型进行流的操作。

ByteArrayInputStream:在构造的时候,需要接受数据源,且是一个数组。
ByteArrayOutputStream:在构造的时候,不用定义数据目的,因为该对象中已经内部封装了可变长度的字节数组。
因为两个流对象都操作的数组,并没有系统资源,不用进行close关闭,就算关闭资源,其方法还是可以调用。
用流的读写思想来操作数组。
流规律:
源设备:键盘(System.in) 硬盘(FileStream) 内存(ArrayStream)
目的设备:控制台(System.out) 硬盘(FileStream) 内存(ArrayStream)

黑马程序员-IO流其他流对象相关推荐

  1. 黑马程序员————IO流2(day19)

    ----------------------ASP.Net+Android+IOS开发----------------------期待与您交流! IO流2 l  BufferedWriter l  B ...

  2. 黑马程序员————IO流1(day18)

    ----------------------ASP.Net+Android+IOS开发----------------------期待与您交流! IO流1 l  其它对象(System) l  其它对 ...

  3. 黑马程序员 IO流

       ------- android培训.java培训.期待与您交流! ----------  IO流 java.io包中的stream类根据它们操作对象的类型是字符还是字节可分为两大类: 字符流和字 ...

  4. 黑马程序员——IO流

    ------<a href="http://www.itheima.com" target="blank">Java培训.Android培训.iOS ...

  5. 黑马程序员————IO流4(day21)

    ----------------------ASP.Net+Android+IOS开发----------------------期待与您交流! IO流4 l  对象的序列化 l  管道流 l  Ra ...

  6. 黑马程序员————IO流------(3)

    ------Java培训.Android培训.iOS培训..Net培训.期待与您交流! ------- File类: 流只能操作数据,若想要用流操作被文件封装的数据信息,必须用file对象. > ...

  7. 黑马程序员————IO流3(day20)

    ----------------------ASP.Net+Android+IOS开发----------------------期待与您交流! IO流3 l  File概述 l  File类常见方法 ...

  8. 黑马程序员--IO流(19天)

    ---------------------- ASP.Net+Android+IOS开发..Net培训.期待与您交流! ---------------------- 缓冲区的出现时为了提高流的操作而出 ...

  9. 黑马程序员——IO 流总结

    ------<a href="http://www.itheima.com"target="blank">Java培训.Android培训.iOS培 ...

最新文章

  1. 集合框架(List的三个子类的特点)
  2. SqLite中的事务
  3. postman参数化 接口响应数据获取符合条件的内容参数化给后面的接口使用
  4. [原创][连载].基于SOPC的简易数码相框 - Nios II SBTE部分(软件部分) - 从SD卡内读取图片文件,然后显示在TFT-LCD上...
  5. OpenCV Laplacian算子
  6. python分组函数_Python中如何按列分组和按自己的函数汇总
  7. make zImage和make uImage的区别和mkimage工具的使用
  8. mybatis的$和#详解分析
  9. 我心中的核心组件(可插拔的AOP)~第十五回 我的日志组件Logger.Core(策略,模版方法,工厂,单例等模式的使用)...
  10. php自带excel,基于php中使用excel的简单介绍_PHP
  11. eclipse运行java程序出现多个问题:内部错误IOConsole Updater
  12. 摄像头实时画面转接到web页面
  13. 收集的一些discuz插件常用插件分享给大家了
  14. deepin linux字体设置,在deepin系统中如何安装系统字体? - Deepin深度系统用户手册...
  15. 内核仿阿里巴巴小说网站源码 PC端+WAP端
  16. 可行性研究报告【列文】2022-5.6
  17. 中科探海的海底掩埋物三维实时成像声呐
  18. 使用SLT系统抽数到hana系统
  19. Classification分类学习
  20. 学生公寓管理系统-javaweb

热门文章

  1. Windows资源监控神器——perfmon
  2. SafeNet呼吁采用KMIP,推出首款基于硬件的企业密钥管理平台
  3. 使用 Visual Studio Code 和 Pandoc 构建一个惊人的 Markdown 编辑器
  4. libev学习系列之二:libev下载
  5. 个人认为最好的Mac端的视频播放软件___movist
  6. unity3d插入android有米广告
  7. Phpstudy的安装及使用(web)
  8. 软件项目管理的十大定律
  9. 2020C证(安全员)考试题库及C证(安全员)作业模拟考试
  10. Flink中TaskManager、Slot和Parallelism