Update 9

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.InputStream;
import java.io.OutputStream;

public class Main {

	private final static int parts = 1024 * 1024 * 10;

	private final static String path = "C:" + File.separator;

	public static void main(String[] args) throws Exception {
		separate();
		consolidate();
	}

	public static void separate() throws Exception {
		byte[] temps = new byte[parts];
		InputStream input = Main.class.getResourceAsStream("FAQ 8-13.rar");
		int nRead;
		int index = 0;
		// 从输入流中读入字节流,然后写到文件中
		while ((nRead = input.read(temps)) > 0) {
			OutputStream output = new FileOutputStream(new File(path, "part" + index++ + ".zip"));
			output.write(temps, 0, nRead);
			output.close();
		}
		input.close();
		System.out.println("SUCCESS");
	}

	public static void consolidate() throws Exception {
		File files = new File(path);
		String[] list;
		list = files.list(new DirFilter());
		
		int nRead;
		byte[] temps = new byte[parts];
		OutputStream output = new FileOutputStream(new File(path, "FAQ.rar"));
		for (String name : list)
		{
			InputStream input = new FileInputStream(new File(path,name));
			while ((nRead = input.read(temps)) > 0) {
				output.write(temps, 0, nRead);
			}
		}
		output.close();
		System.out.println("SUCCESS");
	}
}
// 名称过滤接口,accept返回true才通过过滤
class DirFilter implements FilenameFilter {
	// dir - 被找到的文件所在的目录
	// name - 文件的名称
	public boolean accept(File dir, String name) {
		boolean test = name.matches("part[0-9].*zip");
		return test;
	}
}


你可能感兴趣的:(linux,windows,qq,正则表达式,Gmail)