S
snowrain
Unregistered / Unconfirmed
GUEST, unregistred user!
Filename是被分割的文件的全路径文件名
disksize是被分割成的小文件的大小
filenum是这个被分割的文件要被分成的块数
……
try{
for (int i=0 ;i<filenum;i++)
{
FileInputStream fileinputstream =new FileInputStream(Filename);
FileOutputStream fileoutputstream =new FileOutputStream(Filename+Integer.toString(i) );
BufferedInputStream bufferedinputstream =new BufferedInputStream(fileinputstream);
BufferedOutputStream bufferedoutputstream =new BufferedOutputStream(fileoutputstream);
int n,currentsize=0;
byte[] buff=new byte[disksize];
if ((n=bufferedinputstream.read(buff,disksize*i,buff.length))!=-1)
bufferedoutputstream.write(buff,0,n);
bufferedoutputstream.flush();
bufferedoutputstream.close();
bufferedinputstream.close();
}
}
catch( Exception e3){e3.printStackTrace();}
……
上面我想利用read(buff,disksize*i,……)中disksize*i来标明每次产生的小文件在被分割文件中的offset。
但是不能正常生成各个小文件,只能生成2个,而且第二个是0byte的。
不知我上面的程序哪个地方错了,请指教!(我刚刚开始学习JAVA,请各位大侠讲仔细点)
BTW:
程序同时报出这个异常:
java.lang.IndexOutOfBoundsException
at java.io.BufferedInputStream.read(BufferedInputStream.java:275)
at testui.MainForm.StartSplit_actionPerformed(MainForm.java:199)
at testui.MainForm$4.actionPerformed(MainForm.java:94)
at java.awt.Button.processActionEvent(Button.java:329)
at java.awt.Button.processEvent(Button.java:302)
at java.awt.Component.dispatchEventImpl(Component.java:2595)
at java.awt.Component.dispatchEvent(Component.java:2499)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:319)
at java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:103)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:84)
不知道怎么去分析这个错误输出?
disksize是被分割成的小文件的大小
filenum是这个被分割的文件要被分成的块数
……
try{
for (int i=0 ;i<filenum;i++)
{
FileInputStream fileinputstream =new FileInputStream(Filename);
FileOutputStream fileoutputstream =new FileOutputStream(Filename+Integer.toString(i) );
BufferedInputStream bufferedinputstream =new BufferedInputStream(fileinputstream);
BufferedOutputStream bufferedoutputstream =new BufferedOutputStream(fileoutputstream);
int n,currentsize=0;
byte[] buff=new byte[disksize];
if ((n=bufferedinputstream.read(buff,disksize*i,buff.length))!=-1)
bufferedoutputstream.write(buff,0,n);
bufferedoutputstream.flush();
bufferedoutputstream.close();
bufferedinputstream.close();
}
}
catch( Exception e3){e3.printStackTrace();}
……
上面我想利用read(buff,disksize*i,……)中disksize*i来标明每次产生的小文件在被分割文件中的offset。
但是不能正常生成各个小文件,只能生成2个,而且第二个是0byte的。
不知我上面的程序哪个地方错了,请指教!(我刚刚开始学习JAVA,请各位大侠讲仔细点)
BTW:
程序同时报出这个异常:
java.lang.IndexOutOfBoundsException
at java.io.BufferedInputStream.read(BufferedInputStream.java:275)
at testui.MainForm.StartSplit_actionPerformed(MainForm.java:199)
at testui.MainForm$4.actionPerformed(MainForm.java:94)
at java.awt.Button.processActionEvent(Button.java:329)
at java.awt.Button.processEvent(Button.java:302)
at java.awt.Component.dispatchEventImpl(Component.java:2595)
at java.awt.Component.dispatchEvent(Component.java:2499)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:319)
at java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:103)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:84)
不知道怎么去分析这个错误输出?