java 输出编码为utf-8的文件的方法

文章来源:http://hi.baidu.com/zdz8207/blog/item/5dc39b22f070fbfbd6cae27d.html

 

 

/**
* 输出文件,编码为UTF-8 用记事本另存为:fileContent 全部为英文则为ansi 包含中文则为UTF-8
* @param filePathAndName
* @param fileContent
*/
public static void writeFile(String filePathAndName, String fileContent)
{
   try
   {
    FileOutputStream fos = new FileOutputStream(filePathAndName);
   Writer out = new OutputStreamWriter(fos, "UTF-8");
    out.write(fileContent);
    out.close();
    fos.close();
   } catch (IOException e)
   {
    System.out.println("写文件内容操作出错");
    e.printStackTrace();
   }
}

 

猜你喜欢

转载自aeolus1983.iteye.com/blog/2309273