📄 guigzipper.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 + -