`

java 压缩.gz

阅读更多
public class GzipPcompress {

	public static void main(String args[]) {
		GzipPcompress gzip = new GzipPcompress() ;
		String sourcePathAndName = "F:/download/20150819.txt" ;
		String pressPathAndName = "F:/download/a.gz" ;
		gzip.gzPressFile(sourcePathAndName, pressPathAndName);
		
	}
	
	public void gzPressFile(String  sourcePathAndName ,String pressPathAndName ){
		try {
			BufferedReader in = new BufferedReader(new FileReader(sourcePathAndName));

			BufferedOutputStream out = new BufferedOutputStream(
					new GZIPOutputStream(new FileOutputStream(pressPathAndName)));
			int c;
			while ((c = in.read()) != -1) {
				out.write(c);
			}
			in.close();
			out.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics