import java.io.*; import java.util.Vector; class HTMLTableOutput { public static void main(String args[]) { try { HTMLTableOutput hTO=new HTMLTableOutput(); HTMLTableOutput.ContactPerson cpObj=hTO.new ContactPerson("John", "012-345-6789", "john@fiction.org"); HTMLTableOutput.ContactPerson cpObj2=hTO.new ContactPerson("Joe", "987-654-3210", "joe@fiction.org"); HTMLTableOutput.ContactPerson cpObj3=hTO.new ContactPerson("Mary", "121-212-1212", "mary@fiction.org"); Vector vecContacts=new Vector(); vecContacts.addElement(cpObj); vecContacts.addElement(cpObj2); vecContacts.addElement(cpObj3); File newFile=null; int intCountFile=0; //This loop makes sure that we don't overwrite an existing file. while(true) { newFile=new File("HTMLTableOutput"+intCountFile+".html"); if(newFile.exists()) { ++intCountFile; continue; } break; } RandomAccessFile raf=new RandomAccessFile(newFile, "rw"); raf.writeBytes(""); raf.write(13); raf.write(10); raf.writeBytes("
"); raf.write(13); raf.write(10); //Make the table have 3 columns and width be half the window size raf.writeBytes("Name | Phone | "); raf.writeBytes(nextContact.getName()); raf.writeBytes(" | "); //Output the data for the second cell raf.writeBytes(""); raf.writeBytes(nextContact.getPhone()); raf.writeBytes(" | "); //Output the data for the third cell raf.writeBytes(""); raf.writeBytes(nextContact.getEmail()); raf.writeBytes(" | "); raf.writeBytes(""); raf.write(13); raf.write(10); } raf.writeBytes("
---|