posts - 165, comments - 198, trackbacks - 0, articles - 1
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

java gzip (使用,乱码问题已解决!)

Posted on 2008-12-22 14:35 G_G 阅读(3609) 评论(0)  编辑  收藏 所属分类: javaGeneral




     public   static   void  main(String[] args)  {
        
try   {
        
         String charset 
=   " UTF-8 " ;
         String outfile 
=   " d:\\category.20081218.gz " ;
         BufferedReader in 
=   new  BufferedReader(
          
new  InputStreamReader(
          
new  FileInputStream( " d:\\category.20081218 " ),
          charset));
          
          BufferedOutputStream out 
=
            
new  BufferedOutputStream(
              
new  GZIPOutputStream(
                
new  FileOutputStream(outfile)));
          
          
          System.out.println(
" Writing file " );
          String c;
          
while ((c  =  in.readLine()) != null )
            out.write( (c
+ " \n " ).getBytes(charset));
          in.close();
          out.close();
          System.out.println(
" Reading file " );
          BufferedReader in2 
=
            
new  BufferedReader(
              
new  InputStreamReader(
                
new  GZIPInputStream(
                  
new  FileInputStream(outfile)
                  ),charset
                )
              );
          String s;
          
while ((s  =  in2.readLine())  !=   null )
            System.out.println(s);
        }
  catch (Exception e)  {
          e.printStackTrace();
        }

      }



只有注册用户登录后才能发表评论。


网站导航: