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

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

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

          ??????}


          主站蜘蛛池模板: 教育| 嘉义市| 广南县| 怀仁县| 奉化市| 肃北| 盈江县| 若羌县| 南木林县| 年辖:市辖区| 英德市| 南康市| 长沙县| 根河市| 勃利县| 新郑市| 贺州市| 镇坪县| 邢台市| 兰坪| 台中市| 皮山县| 嘉黎县| 拉孜县| 永顺县| 中山市| 广东省| 潜江市| 夏津县| 高碑店市| 灯塔市| 夏河县| 当阳市| 阿拉善左旗| 榆树市| 叙永县| 呼玛县| 乃东县| 鲜城| 勃利县| 安阳市|