怎么使java输出的文件以UTF-8编码
fileDir=createFileSaveDir();//创建初始文件名StringfileName=createFileName();//创建文件输出流Buffere...
fileDir = createFileSaveDir();// 创建初始文件名 String fileName = createFileName(); // 创建文件输出流 BufferedWriter writer = createFileWriter(fileName);求助大神java创建文件,但怎么设置编码格式为UTF-8,在线等
展开
展开全部
代码如下:
public static BufferedWriter createFileWriter(String name) throws FileNotFoundException, UnsupportedEncodingException {
FileOutputStream outputStream = new FileOutputStream(name);
OutputStreamWriter outputWriter = new OutputStreamWriter(outputStream, "utf-8");
BufferedWriter writer = new BufferedWriter(outputWriter);
return writer;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询