您的当前位置:首页正文

文件转码 如:望京公园 -> %E6%9C%9B%E4%BA%AC%E5%85%AC%E5%9B%AD

2024-12-02 来源:个人技术集锦

File source = new File("f:/test.txt");
File tar = new File("f:/test2.txt");
try {
BufferedReader bReader = new BufferedReader(new FileReader(source));
BufferedWriter bw = new BufferedWriter(new FileWriter(tar));
String line = "";
while ((line = bReader.readLine()) != null) {
line = line.trim();
line = URLEncoder.encode(line, "UTF-8");
bw.write(line);
bw.newLine() ;
bw.flush();
}
bReader.close() ;
bw.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

显示全文