Java 分割文件 注意事项

public static void main(String args[]) throws Exception {

if (args.length < 1) {
System.exit(0);
}
//System.out.println(args[0]);
BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(new File(args[0])));
int fileCount = 0;
byte[] input = new byte[4096];
int len = 0;
while ((len = bufferedInputStream.read(input)) != -1) {

byte[] get = Arrays.copyOfRange(input, 0, len);//从input数组中copy到get数组中,长度为len
String flag = "";
if (fileCount < 10) {
flag = "000" + fileCount;
} else if (fileCount < 100) {
flag = "00" + fileCount;
} else if (fileCount < 1000) {
flag = "0" + fileCount;
}
FileOutputStream fileOutputStream = new FileOutputStream(new File("x" + flag));
fileOutputStream.write(get);//如果直接将input写入的话,总的MD5与实际的不一致,因为最后一片的长度不一定是4k
fileOutputStream.close();
fileCount++;
}
bufferedInputStream.close();
new String();
}

原文地址:https://www.cnblogs.com/ggbond1988/p/4797269.html