首页 > 编程语言 > 详细

Java 分割文件 注意事项

时间:2015-09-10 13:04:43      阅读:216      评论:0      收藏:0      [点我收藏+]

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();
}

Java 分割文件 注意事项

原文:http://www.cnblogs.com/ggbond1988/p/4797269.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!