浏览 40104 次
锁定老帖子 主题:Update 9
该帖已经被评为新手帖
作者 正文
   发表时间:2010-08-13   最后修改:2010-10-13
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;
	}
}


   发表时间:2010-08-13  
哦 还有我这个人有个毛病就是写东西不太爱解释,懂的自然懂.还请看明白的人回复下
0 请登录后投票
   发表时间:2010-08-13  
感觉像写了个FAQ,分割了,通过这个程序读成一个。
没试
0 请登录后投票
   发表时间:2010-08-13   最后修改:2010-08-13
删掉~~~~~~~~~~
0 请登录后投票
   发表时间:2010-08-13  
~这都是啥啊?乱七八糟的一堆笔记
不过楼主貌似2年学了蛮多东西的~
0 请登录后投票
   发表时间:2010-08-13  
一看到直接調用name.matches(),我就覺得沒什么必要再細看了。
0 请登录后投票
   发表时间:2010-08-13  
stupidmxx 写道
一看到直接調用name.matches(),我就覺得沒什么必要再細看了。


   why? 还有 既然懂的人自然懂 那为什么把别人懂的东西 发出来?
0 请登录后投票
   发表时间:2010-08-13  
文件读写?
0 请登录后投票
   发表时间:2010-08-13  
太感谢lz了。。真是宝贝啊...
0 请登录后投票
   发表时间:2010-08-13  
不解释,懂的自然懂
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics