Skip to content

Commit 28607a2

Browse files
author
crazy
committed
2017.04.09 19:36
1 parent 127b72d commit 28607a2

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

JavaBase/poweroff.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
helloworld
1+
hello

JavaBase/src/com/it520/io01/FileInputStreamDemo.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,26 @@
1111
public 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
//关闭流操作

0 commit comments

Comments
 (0)