import java.io.*; public class ImagePageGenerator { private String title; private String sourceDirectory; private String eoln; public ImagePageGenerator( String title, String directory ) { this.title = title; sourceDirectory = directory; eoln = System.getProperty( "line.separator" ); } public void writePage() { String fullname = sourceDirectory + "index.html"; try { BufferedWriter output = new BufferedWriter( new FileWriter(fullname) ); this.writePreamble( output ); this.writeHeader( output ); this.writeBody( output ); this.writePostamble( output ); output.close(); } catch (IOException ex) { System.out.println( "An error occurred writing the file " + fullname ); } } // ----- standard helpers private void writePreamble( BufferedWriter output ) throws IOException { output.write( "" ); output.newLine(); output.write( "" ); output.newLine(); } private void writeHeader( BufferedWriter output ) throws IOException { output.write( "
" ); output.newLine(); output.write( "Filename: " + name + "
" + eoln; } } output.write( body ); } }