67,513
社区成员
发帖
与我相关
我的任务
分享
public class TestCut {
public void cut() {
String readPath = "d:/testcut/vmware.log";
File testFile = new File(readPath);
long num = testFile.length() / 10L;
try {
RandomAccessFile file1 = new RandomAccessFile(testFile, "r");
byte[] min = new byte[1024];
int len = -1;
for(int i = 0; i < 10; i++ ) {
String writePath = "d:/testcut/vmware" + i + ".log";
File testOut = new File(writePath);
RandomAccessFile file2 = new RandomAccessFile(testOut,"rw");
try {
while((len = file1.read(min)) != -1) {
System.out.println(len);//最后一次len值是278
file2.write(min,0,1024);
//file2.write(min,0,len);
if(file2.length() > num) {
break;
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}