(1)根据处理单元来分:
字节流:InputStream , OutputStream.
字符流:Reader ,Writer
(2)根据流向来分:
输入流:InputStream , Reader
输出流:OutputStream , Writer
(3)功能是否直接与数据源/目的地相连
节点流 :直接与数据源或目的地相连的称为节点流
处理流 :不直接与数据源或目的相连称为处理流
这么庞大的体系里面,常用的就那么几个,我们把它们抽取出来,如下图:
public static void main(String[] args) throws IOException { InputStream is =new FileInputStream("C:\\Users\\Administrator\\Desktop\\jdk api 1.8_google.CHM"); OutputStream os = new FileOutputStream("C:\\Users\\Administrator\\Desktop\\software\\jdk api 1.8_google.CHM"); byte[] buf = new byte[1024]; int length = 0; long startTime = System.currentTimeMillis(); while((length = is.read(buf)) != -1){ os.write(buf,0,length); } long endTime = System.currentTimeMillis(); System.out.println("复制耗时"+(endTime-startTime)+"毫秒"); os.close(); is.close(); }
/** * 使用BufferedInputStream,BufferedOutputStream复制文件 * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedInputStream bis = new BufferedInputStream(new FileInputStream("C:\\Users\\Administrator\\Desktop\\jdk api 1.8_google.CHM")); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("C:\\Users\\Administrator\\Desktop\\software\\jdk api 1.8_google.CHM")); byte[] buf = new byte[1024]; int length = 0; long startTime = System.currentTimeMillis(); while((length = bis.read(buf)) != -1){ bos.write(buf,0,length); } long endTime = System.currentTimeMillis(); System.out.println("复制耗时"+(endTime-startTime)+"毫秒"); bos.close(); bis.close(); }
原文:https://www.cnblogs.com/kpsmile/p/11047942.html