本帖最后由 吃阁子的猫 于 2013-8-24 11:16 编辑
public static void main(String[] args) throws Exception {
System.out.println("请输入要分割的文件路径:");
Scanner sc = new Scanner(System.in);
File file = new File(sc.nextLine());
sc.close();
File fi = new File(".temp");
fi.mkdir();
long length = file.length()/5+1;
FileInputStream fis = new FileInputStream(file);
for (int i = 1; i < 5; i++) {
FileOutputStream fos = new FileOutputStream(new File(file,i+""));
byte[] arr = new byte[1024];
int len ;
for (int j = 0; j < length && (len = fis.read())!=-1; j++) {
fos.write(arr,0,len);
}
fos.close();
fis.close();
}
file.delete();
fi.renameTo(file);
}
}
|