ファイルカットマージコード
2991 ワード
/*
*/
import java.io.*;
class SplitFile
{
public static void main(String[] args) throws IOException
{
File file = new File("f:\\1.bmp");
FileInputStream fis = new FileInputStream(file);
byte[] buf = new byte[1024*1024];
int count = 1;
int len = 0;
FileOutputStream fos = null;
while((len=fis.read(buf))!=-1)
{
fos = new FileOutputStream("f:\\splitfile\\"+(count++)+".part");
fos.write(buf,0,len);
fos.close();
}
String info = file.getName()+">"+(count-1);
fos = new FileOutputStream("f:\\splitfile\\"+(count++)+".partconfig");
fos.write(info.getBytes());
fos.close();
System.out.println(count);
fis.close();
}
}
/*
*/import java.io.*;
import java.util.*;
class HeBingFile
{
public static void main(String[] args) throws IOException
{
File f = new File("f:\\splitfile");
File[] files = f.listFiles();
File config = null;
for(File file : files)
{
if(file.getName().endsWith(".hahaconfig"))
{
config = file;
break;
}
}
if(config==null)
{
System.out.println(" ");
return ;
}
BufferedReader bufr = new BufferedReader(new FileReader(config));
String info = bufr.readLine();
String[] infos = info.split(">");
String name = infos[0];
int count = Integer.parseInt(infos[1]);
ArrayList<FileInputStream> al = new ArrayList<FileInputStream>();
for(int x=1; x<=count; x++)
{
File ff = new File("f:\\splitfile\\"+x+".haha");
if(!ff.exists())
{
System.out.println(ff.getName()+".. ");
return;
}
al.add(new FileInputStream(ff));
}
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("F:\\splitfile\\"+name);
byte[] buf = new byte[1024];
int len = 0;
while((len=sis.read(buf))!=-1)
{
fos.write(buf,0,len);
}
fos.close();
sis.close();
}
}