我想将一个大文件拆分成基于大小的部分。我使用随机访问文件。我所做的工作是获取文件的长度,拆分文件并为每个文件设置文件大小文件使用随机文件访问不能正常工作
File file = new File("/home/hello/test.txt");
if(file.exists()){
long filesize = file.length();
int noofparts = 5;
int perfilesize = (int) (filesize/5);
for(int i=0;i<noofparts;i++){
try {
OutputStream os = new FileOutputStream("/home/solomon/test"+i+".txt");
RandomAccessFile racces = new RandomAccessFile(file, "r");
racces.seek(seek);
int read;
for(int j=0;j<perfilesize;perfilesize++){
os.write(racces.readInt());
}
os.flush();
os.close();
seek = seek+perfilesize;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
它拆分,但没有得到适当的输出
INPUT
法国警方正在搜寻总部马里的NE乐Pe的
.....长文本
OUTPUT
RHL eaithqt MnensrgFttaeoa Manloo egontagmsfran doyrmaastaNfaoRe eraaatsih小时FERR
和相同的输出是写在五个文件中
?这样做的风险会不会让文本变得乱七八糟? –