Created
December 21, 2025 16:16
-
-
Save albertus82/18cd3150ef244cf06a41d3d5ae337c49 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io.IOException; | |
| import java.io.UncheckedIOException; | |
| import java.nio.file.Files; | |
| import java.nio.file.Path; | |
| import java.nio.file.StandardOpenOption; | |
| class HtmlSpecialCharsReplacer { | |
| public static void main(final String... args) throws IOException { | |
| try (final var r = Files.lines(Path.of(args[0])); final var w = Files.newBufferedWriter(Path.of(args[0] + ".html"), StandardOpenOption.CREATE_NEW)) { | |
| r.forEachOrdered(line -> { | |
| try { | |
| for (final var c : line.trim().toCharArray()) { | |
| if (c < 128) { | |
| w.append(c); | |
| } | |
| else { | |
| w.append("&#" + (int) c + ";"); | |
| } | |
| } | |
| } | |
| catch (final IOException e) { | |
| throw new UncheckedIOException(e); | |
| } | |
| }); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment