java读取字符串,⽣成txt⽂件/**
* 读取字符串,⽣成txt ⽂件已解决未设置编码时,在项⽬中直接打开⽂件,中⽂乱码问题
* WriteText.writeToText(musicInfo,fileName)直接调⽤
*
* @author ziggo
*
*/
public class WriteText {
public static void writeToText(String musicInfo, String fileName) throws IOException {
// ⽣成的⽂件路径
String path = "G:\\data\\" + fileName + ".txt";
File file = new File(path);
乱码文字生成if (!ists()) {
}
// write 解决中⽂乱码问题
// FileWriter fw = new FileWriter(file, true);
OutputStreamWriter fw = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
BufferedWriter bw = new BufferedWriter(fw);
bw.write(musicInfo);
bw.flush();
bw.close();
fw.close();
}
当调⽤⽅法执⾏时,会⽣成⾃定义⽂件名的txt⽂件,使⽤场景较少,效果如下
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论