- import java.io.*;
- class Split
- {
- public static void main(String[] args)throws IOException
- {
- splitFile();
- }
-
- public static void splitFile() throws IOException
- {
- FileInputStream fis = new FileInputStream("c:\\2.exe");
- FileOutputStream fos = null;
-
- byte[] buf = new byte[1024*1024];//建立一个大小为1Mb的缓冲区
- int len = 0;
- int count = 1;
- int num = 0;
- while((len=fis.read(buf))!=-1)
- {
- if(num>1023)
- {
- fos = new FileOutputStream("c:\\splitfiles\\"+count+++".part",true);
- num = 0;
- }
- else
- {
- fos = new FileOutputStream("c:\\splitfiles\\"+count+".part",true);
- fos.write(buf,0,len);
- num++;
- fos.close();
- }
- }
- fis.close();
- }
- }
复制代码
//谢谢zengming13的思路 |