Skip to content

Instantly share code, notes, and snippets.

@albertus82
Created December 21, 2025 16:16
Show Gist options
  • Select an option

  • Save albertus82/18cd3150ef244cf06a41d3d5ae337c49 to your computer and use it in GitHub Desktop.

Select an option

Save albertus82/18cd3150ef244cf06a41d3d5ae337c49 to your computer and use it in GitHub Desktop.
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