1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path;
public class Main { public static void main(String[] args) throws IOException { String codes = "C:/Users/dcsuibian/study/疯狂Java讲义/codes"; Files.walk(Path.of(codes)) .filter(path -> path.toString().endsWith(".java")) .forEach(path -> { try { String s = Files.readString(path, Charset.forName("GBK")); Files.writeString(path, s, Charset.forName("UTF-8")); } catch (IOException e) { System.out.println("出错的文件:" + path); e.printStackTrace(); } }); } }
|