甜咖啡

          我的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 甜咖啡 閱讀(220) 評(píng)論(0)  編輯  收藏


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           

          導(dǎo)航

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

          統(tǒng)計(jì)

          常用鏈接

          留言簿(1)

          我參與的團(tuán)隊(duì)

          隨筆檔案

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 尚志市| 南康市| 青龙| 岳普湖县| 忻州市| 柏乡县| 防城港市| 洞头县| 墨玉县| 东至县| 柘城县| 安陆市| 陇西县| 宁武县| 虎林市| 阜城县| 竹北市| 彭阳县| 丹凤县| 九龙县| 禹城市| 三明市| 崇文区| 钟山县| 舞钢市| 阜南县| 英吉沙县| 平阴县| 太原市| 宜章县| 高阳县| 罗田县| 仁布县| 闻喜县| 龙游县| 云梦县| 资中县| 大英县| 蒙山县| 中山市| 梧州市|