不知道什么原因。我加了缓冲区是可以的。- package test;
- import java.io.BufferedInputStream;
- import java.io.BufferedOutputStream;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- public class SplitFile {
- public static void main(String[] args) throws IOException {
- BufferedInputStream fis = new BufferedInputStream( new FileInputStream("1.avi"));
- byte[]buf = new byte[1024*1024*5];
- int len = 0;
- BufferedOutputStream fos = null;
- int count = 1;
-
- while((len = fis.read(buf))!=-1){
- fos = new BufferedOutputStream(new FileOutputStream((count++)+".part"));
- fos.write(buf,0,len);
-
- fos.close();
- }
- fis.close();
-
- }
- }
复制代码 |