| :IO流       (1)分类             字节流:                   输入流:                         InputStream(抽象类)                               intread()                               intread(byte[] bys)                           FileInputStream(常用基本流)                           BufferedInputStream                   输出流:                         OutputStream(抽象类)                               write(intby)                               write(byte[]bys,int index,int len)                           FileOutputStream(常用基本流)                           BufferedOutputStream               字符流:                   输入流:                         Reader(抽象类)                               intread()                               intread(char[] chs)                             FileReader(常用基本流)                             BufferedReader                               String readLine()                   输出流:                         Writer(抽象类)                               write(intch)                               write(char[]chs,int index,int len)                           FileWriter(常用基本流)                           BufferedWriter                               write(String line)                               void newLine()         (2)到底使用谁?             用记事本打开能读懂的,就用字符流。             否则,用字节流。             如果你根本就不知道,用字节流。         (3)复制文本文件(了解):             9种方式:                   字节流:                         4种                               基本流一次读写一个字节                               基本流一次读写一个字节数组                               高效流一次读写一个字节                               高效流一次读写一个字节数组                   字符流:                         5种                               基本流一次读写一个字符                               基本流一次读写一个字符数组                               高效流一次读写一个字符                               高效流一次读写一个字符数组                               高效流一次读写一个字符串               一般来说,明明知道是文本文件,那么,肯定不用字节流。             那么,如果是使用字符流,有5种方式,选择哪一种呢?             一般都选择高效流读写一个字符串的方式。                 代码体现:                   数据源:c:\\a.txt                   目的地:d:\\b.txt                     BufferedReader br = new BufferedReader(newFileReader("c:\\a.txt"));                   BufferedWriter bw = new BufferedWriter(newFileWriter("d:\\b.txt"));                     String line = null;                   while((line=br.readLine())!=null)                   {                         bw.write(line);                         bw.newLine();                         bw.flush();                   }                     bw.close();                   br.close();         (4)复制二进制流数据:(图片,视频,音频等)             字节流:                         4种                               基本流一次读写一个字节                               基本流一次读写一个字节数组                               高效流一次读写一个字节                               高效流一次读写一个字节数组               一般来说,我们选择使用高效流一次读写一个字节数组               代码体现:                   数据源:c:\\a.jpg                   目的地:d:\\b.jpg                     BufferedInputStream bis = new BufferedInputStream(newFileInputStream("c:\\a.jpg"));                   BufferedOutputStream bos = newBufferedOutputStream(new FileOutputStream("d:\\b.jpg"));                     byte[] bys = new byte[1024];                   int len = 0;                   while((len=bis.read(bys))!=-1)                   {                         bos.write(bys,0,len);                   }                     bos.close();                   bis.close();   
 |