123456789101112131415161718192021222324252627282930313233public class MarkdownDemo { public static void main(String[] args) throws IOException { String blogPath = "D:\\data\\clawhub"; String oldDomain = "https://cdn.jsdelivr.net/gh"; String newDomain = "https://xxxx"; execute(Paths.get(blogPath), oldDomain, newDomain); } private static void execute(Path blogPath, String oldDomain, String newDomain) { try (Stream<Path> stream = Files.list(blogPath)) { stream.forEach((Path path) -> { if (Files.isDirectory(path)) { execute(path, oldDomain, newDomain); } else { replace(path, oldDomain, newDomain); } }); } catch (IOException e) { throw new RuntimeException(e); } } private static void replace(Path path, String oldDomain, String newDomain) { try { byte[] bytes = Files.readAllBytes(path); String str = new String(bytes); str = str.replaceAll(oldDomain, newDomain); Files.write(path, str.getBytes(StandardCharsets.UTF_8), StandardOpenOption.TRUNCATE_EXISTING); } catch (IOException e) { throw new RuntimeException(e); } }}