甜咖啡

          我的IT空間

          java 讀寫文件

           

                  // 寫文件UTF-8格式 寫一行
            public static void writerTxtFile(String filePath, String text) {
            OutputStreamWriter fs;
            try {
            fs = new OutputStreamWriter(new FileOutputStream(filePath, true), "UTF-8");
            fs.write(text + "\n");
            fs.flush();
            fs.close();
            } catch (UnsupportedEncodingException e1) {
            e1.printStackTrace();
            } catch (FileNotFoundException e1) {
            e1.printStackTrace();
            } catch (IOException e) {
            e.printStackTrace();
            }
            }
           
            // 寫文件UTF-8格式 寫一行
            public static void writerStringBuffer(String filePath, StringBuffer text) {
            OutputStreamWriter fs;
            try {
            fs = new OutputStreamWriter(new FileOutputStream(filePath, true), "UTF-8");
            fs.write(text + "\n");
            fs.flush();
            fs.close();
            } catch (UnsupportedEncodingException e1) {
            e1.printStackTrace();
            } catch (FileNotFoundException e1) {
            e1.printStackTrace();
            } catch (IOException e) {
            e.printStackTrace();
            }
            }
           
            // 寫文件
            public static void writerTxtFile(String filePath, List<String> list) {
            OutputStreamWriter fs;
            try {
            fs = new OutputStreamWriter(new FileOutputStream(filePath, true), "UTF-8");
            for(int i=0; i<list.size(); i++){
            fs.write(list.get(i) + "\n");
            }
            fs.flush();
            fs.close();
            } catch (UnsupportedEncodingException e1) {
            e1.printStackTrace();
            } catch (FileNotFoundException e1) {
            e1.printStackTrace();
            } catch (IOException e) {
            e.printStackTrace();
            }
            }

           

          posted on 2011-11-04 12:33 甜咖啡 閱讀(219) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          導航

          <2011年11月>
          303112345
          6789101112
          13141516171819
          20212223242526
          27282930123
          45678910

          統計

          常用鏈接

          留言簿(1)

          我參與的團隊

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 景洪市| 东至县| 阿克苏市| 普洱| 安塞县| 荆州市| 石景山区| 昌宁县| 巴林左旗| 枞阳县| 武陟县| 元氏县| 涿鹿县| 基隆市| 涿州市| 子洲县| 东乡族自治县| 东山县| 黄山市| 镇原县| 云南省| 蕲春县| 塔河县| 永胜县| 缙云县| 商洛市| 衡南县| 临猗县| 松滋市| 观塘区| 瑞丽市| 锡林浩特市| 平湖市| 美姑县| 三都| 永吉县| 五大连池市| 苍溪县| 吴堡县| 墨江| 云龙县|