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();
		}
	}
}

猜你喜欢

转载自see-you-again.iteye.com/blog/2237919
今日推荐