posts - 165, comments - 198, trackbacks - 0, articles - 1
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          java gzip (使用,亂碼問題已解決!)

          Posted on 2008-12-22 14:35 G_G 閱讀(3627) 評論(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();
          ????????}

          ??????}


          主站蜘蛛池模板: 乌拉特中旗| 浏阳市| 四会市| 友谊县| 镇巴县| 崇仁县| 彭州市| 大厂| 铁岭县| 厦门市| 新龙县| 张北县| 汪清县| 河间市| 澎湖县| 贵阳市| 夏津县| 陇川县| 沅江市| 二连浩特市| 如皋市| 舟曲县| 杂多县| 宝兴县| 梁平县| 阳朔县| 昌图县| 黔西县| 阿城市| 那坡县| 军事| 陈巴尔虎旗| 隆子县| 东丰县| 南乐县| 兴安县| 海丰县| 锦屏县| 元阳县| 三穗县| 阿瓦提县|