import java.io.*;
import java.util.*;
class SplitFile
{
public static void main(String[] args) throws IOException
{
splitFile(); //切割
merge(); //缝合
}
public static void merge() throws IOException
{
ArrayList<FileInputStream> al = new ArrayList<FileInputStream>();
for (int x=1; x<=3; x++)
{
al.add(new FileInputStream("E:\\Ziliao\\Java\\practice\\day_one\\"+x+".part"));
}
final Iterator<FileInputStream> it = al.iterator();
Enumeration<FileInputStream> en = new Enumeration<FileInputStream>()
{
public boolean hasMoreElements()
{
return it.hasNext();
}
public FileInputStream nextElement()
{
return it.next();
}
};
SequenceInputStream sis = new SequenceInputStream(en);
FileOutputStream fos = new FileOutputStream("E:\\Ziliao\\Java\\practice\\repear.jpg");
byte[] buf = new byte[1024];
int len =0;
while ((len=sis.read(buf))!=-1)
{
fos.write(buf,0,len);
}
fos.close();
sis.close();
}
public static void splitFile() throws IOException
{
FileInputStream fis = new FileInputStream("E:\\Ziliao\\Java\\practice\\1.jpg");
FileOutputStream fos = null;
byte[] buf = new byte[800*800];
int len = 0;
int count =1;
while ((len=fis.read(buf))!=-1)
{
fos = new FileOutputStream("E:\\Ziliao\\Java\\practice\\day_one\\"+(count++)+".part");
fos.write(buf,0,len);
fos.close();
}
fis.close();
}
}
IO练习(拆分和组合一个文件)
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 小学语文修改病句的方法 修改病句是小学语文考试中常见的题型,在修改病句之前,我们应该清晰的了解有哪些病句现象,下面...