import java.io.*; import java.util.*; public class OrdersHtml { public static void main(String[] args) throws IOException{ File output = new File("output.html"); //create a new file for output. output.createNewFile(); //create a new file if necessary. BufferedWriter out = new BufferedWriter(new FileWriter(output)); String fname = "Details.csv"; StringTokenizer st; int total = 1, qty = 0; double price_unit = 0., sum = 0.; BufferedReader in = new BufferedReader(new FileReader(fname)); out.write("Web Report

"); out.write(""); try{ in = new BufferedReader(new FileReader(fname)); String line = in.readLine();//read into the column header. line = in.readLine(); // to skip the column header; ie: do not process the column header. while(line != null){ st = new StringTokenizer(line, ","); while(st.hasMoreTokens()){ // linenum > 1 means to skip the header of String st2 = (String) st.nextToken(); //the Details.csv file. (it is String, thus it can't be PARSE!) st2 = st2.trim(); if(total%5 == 2){ //Print the 2nd field of the .csv file (which is the product name) out.write(""); //write the product's name to the output file. } if(total%5 == 3){ //Assume that there are 5 fields in this data file. Print the 3rd field price_unit = Double.parseDouble(st2); out.write(""); //write the per unit price to the output file. } if(total%5 == 4){ //Assume that there are 5 fields in this data file. Print the 4th field qty = Integer.parseInt(st2); sum = price_unit*qty; sum = (double) Math.round(sum*100)/100; out.write(""); //write the quantity & the sum to the output file. } total++; } line = in.readLine(); } } catch(Exception e){ System.out.println(e); System.exit(0); } Process p = Runtime.getRuntime().exec("C:\\Program Files\\Internet Explorer\\iexplore.exe D:\\data\\Jen\\CS203\\output.html"); out.write("
" + st2 + "$" + st2 + "" + qty + "$" + sum + "
"); out.close(); } //end of main() } //end of class File_IO5{}