本帖最后由 郑元皓 于 2013-5-1 14:02 编辑
package day20;
import java.io.*;
import java.util.*;
public class SplitFile {
/**
* @param args
*/
public static void main(String[] args)throws IOException {
// TODO Auto-generated method stub
//splitFile();
merge();
}
public static void merge()throws IOException
{
ArrayList<FileInputStream> a1=new ArrayList<FileInputStream>();
for(int x=1;x<=5;x++)
{
a1.add(new FileInputStream("D:\\JAVA123\\myproject\\acc\\"+x+".cpai"));
}
final Iterator<FileInputStream>it=a1.iterator();
Enumeration<FileInputStream> en=new Enumeration<FileInputStream>()
{
public boolean hasMoreElenents()
{
return it.hasNext();
}
public FileInputStream nextElement()
{
return it.next();
}
};
SequenceInputStream sis=new SequenceInputStream(en);
FileOutputStream fos=new FileOutputStream("D:\\JAVA123\\myproject\\acc\\小耗子1.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("D:\\JAVA123\\myproject\\acc\\小耗子.jpg");
FileOutputStream fos=null;
byte[] buf=new byte[1024*10];
int len=0;
int count=1;
while((len=fis.read(buf))!=-1)
{
fos=new FileOutputStream("D:\\JAVA123\\myproject\\acc\\"+(count++)+".cpai");
fos.write(buf,0,len);
fos.close();
}
fis.close();
}
}
为什么Enumeration<FileInputStream> en=new Enumeration<FileInputStream>()这里一直报错啊。好郁闷的 |