import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.SequenceInputStream;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
/**
* 文件的切割与合并
* @author Sugar
*
*/
public class SpliteFileIO {
public static void main(String[] args) throws IOException {
ArrayList<InputStream> arrayList;
// 文件的切割与合并
FileOutputStream fileOutputStream = null;
FileInputStream fileInputStream = new FileInputStream("xiao.png");
byte[] by = new byte[1024 * 100];
int len = 0;
int count = 0;
arrayList = new ArrayList<InputStream>();
while ((len = fileInputStream.read(by)) != -1) {
fileOutputStream = new FileOutputStream((count++) + ".part");
fileOutputStream.write(by, 0, len);
fileOutputStream.close();
}
fileInputStream.close();
arrayList.add(new FileInputStream("0.part"));
arrayList.add(new FileInputStream("1.part"));
Iterator<InputStream> iterator = arrayList.iterator();
Enumeration<InputStream> enumeration = new Enumeration<InputStream>() {
@Override
public boolean hasMoreElements() {
// TODO Auto-generated method stub
return iterator.hasNext();
}
@Override
public InputStream nextElement() {
// TODO Auto-generated method stub
return iterator.next();
}
};
SequenceInputStream sequenceInputStream = new SequenceInputStream(
enumeration);
FileOutputStream fileOutputStream2 = new FileOutputStream("xiao_1.png");
byte[] bys = new byte[1024];
int lens = 0;
while ((lens = sequenceInputStream.read(bys)) != -1) {
fileOutputStream2.write(bys, 0, lens);
}
sequenceInputStream.close();
fileOutputStream2.close();
}
}
java io文件的切割与合并(图片)
最新推荐文章于 2021-02-12 15:45:51 发布