⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guigzipper.java

📁 java应用开发详解
💻 JAVA
字号:
import java.io.*;
import java.util.zip.*;
import javax.swing.*;

public class GUIGZipper 
{
	
	//后缀名
	public final static String GZIP_SUFFIX = ".gz";

  	public static void main(String[] args) 
  	{

    		JFrame parent = new JFrame(); 
    		JFileChooser fc = new JFileChooser();
    		fc.setDialogTitle("Please choose a file to gzip: ");
    		
    		//设置提示语
    		fc.setApproveButtonToolTipText(
			"Select a file, then press this button to gzip it");
    
    		fc.setApproveButtonMnemonic('g');

    		while (true) 
    		{
      			int result = fc.showDialog(parent, "GZIP" );
      			if (result == JFileChooser.APPROVE_OPTION) 
      			{
        			try 
        			{
          				File f = fc.getSelectedFile();
          				if (f == null) 
          				{
            					System.out.println("Can only gzip files, not directories");
            					break;
          				}
          				FileInputStream fin = new FileInputStream(f);
          				FileOutputStream fout = new FileOutputStream(f.getAbsolutePath()+ GZIP_SUFFIX);
          				GZIPOutputStream gzout = new GZIPOutputStream(fout);
          			
          				      			
      					int c=-1;
      					while ((c = fin.read()) != -1)
      					{
           					gzout.write(c);
           				}
          				
          				
          				gzout.close(); 
          				fin.close();
          				fc.rescanCurrentDirectory();
        			}
        			catch (IOException e) 
        			{
          				System.err.println(e);
        			}
      			}
      			else 
      			{
        			parent.dispose();
        			break;
      			}
    		}
    
   		System.exit(0);
  	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -