try {
//以GBK读入
File fileName = new File("E:\\工作内容\\纯真ip数据\\ip\\纯真ip.txt");
FileInputStream fr = new FileInputStream(fileName);
BufferedReader br = new BufferedReader(new InputStreamReader(fr, "GBK"));
//以UTF-8写入
File wfileName = new File("E:\\工作内容\\纯真ip数据\\ip\\数据中心\\数据中心.txt");
FileOutputStream fw = new FileOutputStream (wfileName);
OutputStreamWriter pw = new OutputStreamWriter (fw, "UTF-8");
String line = "";
while ((line = br.readLine()) != null) {
if (line.contains("数据中心")) {
System.out.println("写入一条 : " + line);
pw.write(line+"\r\n");
pw.flush();
}
}
br.close();
fr.close();
pw.close();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
java 文件编码GBK转UTF-8
最新推荐文章于 2024-07-03 02:45:55 发布