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

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();
  }

你可能感兴趣的:(文件转码 如:望京公园 -> %E6%9C%9B%E4%BA%AC%E5%85%AC%E5%9B%AD)