java io 性能问题,急用
程序实现文件读写,但是速度慢,请问怎么才能优化一下。
try{
if ( simpleFile.exists() && simpleFile.isFile() )
{
//FileInputStream fin = new FileInputStream(simpleFile.getAbsolutePath());
DataInputStream fin = new DataInputStream(new BufferedInputStream(
new FileInputStream(simpleFile.getAbsolutePath())));
System.out.println("enter0");
int index1 = simpleFile.getAbsolutePath().indexOf(".");
String name = simpleFile.getAbsolutePath().substring(0, index1);
SimpleFile temp = new SimpleFile(name);
temp.create();
DataOutputStream fout = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(name + "\\" +
simpleFile.getName() + index)));
System.out.println("original file name");
System.out.println(name + "\\" + simpleFile.getName() + index);
byte[] buf = new byte[1024*1024];
fin.skip(start);
while (size >= 1024*1024) {
int readbytes = fin.read(buf,0,1024*1024);
System.out.println("readbytes :" + readbytes);
size -= readbytes;
fout.write(buf);
}
System.out.println("size :" + size);
fin.read(buf, 0, (int) size);
fout.write(buf, 0, (int) size);
fout.flush();
fin.close();
fout.close();
}
}catch(Exception e){
e.printStackTrace();
System.out.println(e.getMessage());
}