需要的 pom包
cn.hutool hutool-all5.7.14
public static void main(String[] args) throws UnsupportedEncodingException {
//此为 当前项目下 latin1 编码的 文件
String txtPath = System.getProperty("user.dir") + File.separator + "base.txt";
//此为 导出文件
String txtNewPath = System.getProperty("user.dir") + File.separator + "newbase.txt";
FileReader fileReader = FileReader.create(new File(txtPath));
FileWriter fileWriter = FileWriter.create(new File(txtNewPath));
List strings = fileReader.readLines();
List newString = new ArrayList<>(strings.size());
for (String linesStr : strings) {
String encodeStr = new String(linesStr.getBytes("iso-8859-1"),"gb2312");
newString.add(encodeStr);
System.out.println(encodeStr);
}
fileWriter.writeLines(newString);
}
测试代码
//测试代码
private static void test() throws UnsupportedEncodingException {
String testStr= ""112" "À¶É«Ò©Ë®"";
String encodeStr = new String(testStr.getBytes("iso-8859-1"),"gb2312");
System.out.println(encodeStr);
}
// 转换的数据为:
// "112" "蓝色药水"



