FileClean1.javaimport java.io.*;
class FileClean1 {
public static void main( String[] args )
{
int ch = 0;
if ( args.length != 2 ) {
System.err.println( "usage: java FileClean1 source dest" );
System.exit( 0 );
}
byte [] amp = "&".getBytes();
byte [] lt = "<".getBytes();
byte [] gt = ">".getBytes();
try (
FileInputStream in = new FileInputStream( args[0] );
FileOutputStream out = new FileOutputStream( args[1] );
)
{
out.write(String.format("<html>%n").getBytes());
out.write(String.format("<pre>%n").getBytes());
while ( true ) {
ch = in.read();
if (ch == -1) break;
else if (ch == '&') out.write(amp);
else if (ch == '<') out.write(lt);
else if (ch == '>') out.write(gt);
else out.write(ch);
}
out.write(String.format("<//pre>%n").getBytes());
out.write(String.format("<//html>%n").getBytes());
out.close();
in.close();
} catch (IOException e) {
System.err.println( "IO error "+e );
}
}
}
Maintained by John Loomis, updated Mon Feb 04 15:09:14 2019