public static void splitFile()throws IOException
{
FileInputStream fis = new FileInputStream("d:\\java\\1.bmp");
FileOutputStream fos = null;
byte[] buf = new byte[1024*1024];
int len = 0;
int count = 1;
while((len=fis.read(buf))!=-1)
{
fos = new FileOutputStream("d:\\java\\splitfiles"+(count++)+".part");
fos.write(buf,0,len);
fos.close();
}
fis.close();
}//运行程序,但是出不来效果作者: 刘基军 时间: 2011-12-23 16:19
输入流"d:\\java\\1.bmp",存在吗? 作者: 李楠 时间: 2011-12-23 16:19
byte[] buf = new byte[1024*1024];
你这个定义的也太大了吧。这可是一个G。。
你改小了就可以了。作者: 杨强 时间: 2011-12-23 16:51 本帖最后由 杨强 于 2011-12-23 16:53 编辑
public static void fenGe() throws IOException{
File f = new File("psb.jpg");
long l = f.length()%5 == 0 ? f.length()/5 :f.length()/5 +1;//分成5份
int filename=1;//定义个分割后的文件名
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(f));
FileOutputStream fos = new FileOutputStream(filename+"");
int b ;
int len =0; //用来判断一份是否写满 写满就写下一份
while((b=bis.read()) != -1){
fos.write(b);
if(++len ==l){
fos.close();
fos = new FileOutputStream(++filename+"");
len=0;
}