甜咖啡

我的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 甜咖啡 阅读(201) 评论(0)  编辑  收藏


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


网站导航:
 

导航

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

统计

常用链接

留言簿(1)

我参与的团队

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜