File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- helloworld
1+ hello
Original file line number Diff line number Diff line change 1111public class FileInputStreamDemo {
1212 public static void main (String [] args ) throws IOException {
1313 //定义一个file对象
14- File f1 =new File ("poweroff.txt" );
15- File f2 =new File ("copy.txt" );
14+ final int BUFFER_SIZE =1024 ;//定义数组常量,便于修改
15+ File f1 =new File ("123.avi" );
16+ File f2 =new File ("copy.avi" );
1617 System .out .println (f1 .getAbsolutePath ());
1718 //定义流对象
1819 InputStream fis =new FileInputStream (f1 );
1920 OutputStream fos =new FileOutputStream (f2 );
2021 //流操作
21- byte [] b1 =new byte [5 ];//数组中需要定义长度
22+ byte [] b1 =new byte [BUFFER_SIZE ];//数组中需要定义长度
2223 int len =0 ;
23- // len=fis.read(b1);
24+ len =fis .read (b1 );
2425 while (len !=-1 ){
25- len =fis .read (b1 );
2626 //String str=new String(b1,0,len);
2727 //System.out.println(str);
2828 fos .write (b1 , 0 , len );
29+ len =fis .read (b1 );
30+ /*fos.write(b1, 0, len);
31+ len=fis.read(b1);
32+ 注意这两句话的顺序,写反了容易出现问题,
33+ 因为前面len=fis.read(b1)已经做了一次读操作了*/
2934 }
3035 System .out .println ();
3136 //关闭流操作
You can’t perform that action at this time.
0 commit comments