使用java.io写txt的时候指定编码为Unicode,但是java写完之后编码会变成Unicode big endian!!!
经过百度多次搜索之后都大家都说将编码指定为“UTF-16LE”,但是进过测试,居然乱码了。。。
未果,所以自己再次多方搜索,无意间看见有人指定读取淘宝助理csv使用x-UTF-16LE-BOM编码,经过测试后写出的txt编码为Unicode;
以下是使用x-UTF-16LE-BOM编码直接将文字写txt的Unicode编码代码
public void saveData(String filePath, String content) throws IOException{
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePath), "x-UTF-16LE-BOM"));
writer.write(content);
writer.flush();
writer.close();
}