public class Test1_Split {
/**
* 把指定的文件切割成10M大小的文件,最后一个文件可以不到10M
* 创建一个输入流,
* 定义一个byte[]数组,确定每次读取10M的内容,
* 创建一个输出流,吧每一次读取的内容存储到不同的文件中
* @throws IOException
*
*/
public static void main(String[] args) throws IOException {
split();
//study2();
}
public static void study2() throws FileNotFoundException, IOException {
//合并切割后的文件
File file = new File("E:/heima/split/split1");
File[] subFiles = file.listFiles();
Vector<FileInputStream> v = new Vector<>();
for (int i = 0; i < subFiles.length; i++) {
FileInputStream fis = new FileInputStream(subFiles[i]);
v.addElement(fis);
}
Enumeration<FileInputStream> en = v.elements();
SequenceInputStream sis = new SequenceInputStream(en);
FileOutputStream fos = new FileOutputStream("E:/heima/split/1.zip");
int len ;
byte[] arr = new byte[1024*1024*10];
while ((len = sis.read(arr)) != -1 ) {
fos.write(arr,0,len);
}
sis.close();
fos.close();
|