?????????????Java???????????????????????????????????????????巽?????£?
????Gzip??????????
?????????????????GZip?????
????package date0805.demo1;
????import java.io.BufferedInputStream;
????import java.io.BufferedOutputStream;
????import java.io.File;
????import java.io.FileInputStream;
????import java.io.FileOutputStream;
????import java.io.InputStream;
????import java.io.OutputStream;
????import java.util.zip.GZIPOutputStream;
????public class GZipRunnable implements Runnable {
????private final File file;
????public GZipRunnable(File file) {
????this.file=file;
????}
????@Override
????public void run() {
????if(!file.getName().endsWith(".gz")) {
????File outputFile=new File(file.getParent()??file.getName()+".gz");
????if(!outputFile.exists()) {
????CountTime countTime = new CountTime(file);
????Thread t=new Thread(countTime);
????t.start();
????try(
????InputStream in =new BufferedInputStream(new FileInputStream(file));
????OutputStream out=new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(outputFile)));
????) {
????int b;
????while((b=in.read())!=-1)
????out.write(b);
????out.flush();
????} catch(Exception ex) {
????ex.printStackTrace();
????}
????t.interrupt();
????} else {
????System.out.println(outputFile+"?????????????????!");
????}
????}
????}
????}
??????????????е?????
?????????????????????????е???????????????????????????????????????????????????????
????package date0805.demo1;
????import java.io.File;
????import java.util.concurrent.ExecutorService;
????import java.util.concurrent.Executors;
????public class GZipFiles {
????private final static int THREAD_COUNT=4;
????private static ExecutorService service=Executors.newFixedThreadPool(THREAD_COUNT);
????public static void GZip(File fileArgs) {
????if(!fileArgs.isDirectory()) {
????GZipRunnable gZipRunnable = new GZipRunnable(fileArgs);
????service.submit(gZipRunnable);
????}
????else {
????File[] files = fileArgs.listFiles();
????for(File f:files) {
????GZip(f);
????}
????}
????}
????public static void shutdown() {
????service.shutdown();
????}
????}
??????????
????package date0805.demo1;
????import java.io.File;
????public class CountTime implements Runnable {
????private File file;
????public CountTime(File file) {
????super();
????this.file = file;
????}
????@Override
????public void run() {
????System.out.println("???????"+file.getAbsolutePath());
????try {
????while(true) {
????System.out.print(".");
????Thread.sleep(1000);
????}
????}catch (InterruptedException e) {
????System.out.println();
????System.out.println(file.getAbsolutePath()+".gz??????????");
????}
????}
????}
????????????
????package date0805.demo1;
????import java.io.File;
????public class Test {
????public static void main(String[] args) {
????File file=new File("D://????????");
????GZipFiles.GZip(file);
????GZipFiles.shutdown();
????}
????}