import java.io.*;
import java.util.zip.*;
//import java.io.ByteArrayOutputStream;
public class UTF8IntoGZ {
private GZIPOutputStream gzos = null;
private String source=new String ("以上两种方……");
private byte[] utf8Byte= null;
//private ByteArrayInputStream utf8Stream = null;
private PrintStream ps = null;
public UTF8IntoGZ()
{
}
public void generateGZFile()
{
try
{
utf8Byte = source.getBytes("UTF-8");
gzos = new GZIPOutputStream( new FileOutputStream("D:\\utf8.html.gz"));
ps = new PrintStream(gzos,true);
ps.write(utf8Byte);
ps.close();
gzos.finish();
}
catch(IOException e)
{
System.err.println("IO Error:" + e.getMessage());
}
}
public static void main(String[] args)
{
UTF8IntoGZ test = new UTF8IntoGZ();
test.generateGZFile();
}
}
通过