java - I am having trouble running my program that creates html templates each time it is ran -


i writing program in java creates html template each time ran. reads input bio txt file made of 4 headings , paragraphs 1 line each. takes txt , stores headings , paragraphs parallel array. have array written html file. problem when run there no input onto file , says reader never closed. here's program , output. thank suggestions.

package edu.txstate.cs3320.qwt1;  import java.util.arraylist; import java.io.bufferedreader; import java.io.filereader; import java.io.filewriter; import java.io.ioexception; import java.io.bufferedwriter;   public class bio2 {      private static final string output_file = "./iofiles/bio.html";     private static final string input_file = "./iofiles/bio.txt";     private static final string title = "my life";      private static bufferedwriter writer = null;      private static arraylist <string> headings = new arraylist <> ();     private static arraylist <string> paragraphs = new arraylist <> ();      //methods before main      private static void initialize (string filename) {         try {             writer = new bufferedwriter(new filewriter(filename));         }catch(ioexception e) {             e.printstacktrace();         }     }      private static void readparagraphs(string inputfilename) {         final int numberofparagraphs = 4;          try {         bufferedreader reader = new bufferedreader(new filereader(inputfilename));          for(int = 0; i<numberofparagraphs;i++) {             string headerline = reader.readline();             if(headerline != null) headings.add(headerline);             string paragraphline = reader.readline();             if(paragraphline != null) paragraphs.add(paragraphline);          }         }catch (ioexception e) {             e.printstacktrace();         }      }     private static void writehtml(string anhtmlstring) {          try {             writer.write(anhtmlstring);             writer.flush();         }catch(ioexception e) {             e.printstacktrace();         }     }      private static void writeparagraphs() {         for(int i=0; i<headings.size();i++) {             writehtml(htmltags.h1_start + headings.get(i)+htmltags.h1_end);             writehtml(htmltags.paragraph_start);             writehtml(paragraphs.get(i));             writehtml(htmltags.paragraph_end);         }     }      private static void writebio(string title) {         writehtmlopening(title);         writeparagraphs();         writehtmlclosing();     }       private static void writehtmlopening(string title) {         writehtml(htmltags.html_header_start);         writehtml(htmltags.title_start + title + htmltags.title_end);         writehtml(htmltags.html_header_end);         writehtml(htmltags.body_start);     }       private static void writehtmlclosing() {         writehtml(htmltags.body_end);         writehtml(htmltags.html_end);     }        public static void main(string[] args) {         initialize(output_file);         writebio(title);         readparagraphs(input_file);         system.out.println("completed");      } } 

<!doctype html>   <html>  <head>  <meta charset="iso-8859-1">  <title>my life</title><style>   h1 {text-align:center;}   </style>   </head>    <body></body></html>

here bio.txt input file

[h1] i? name billy. senior cs major. [h1] interests? develop skillset in software , web development , possibly start career in it. [h1] why taking class? taking class because i'd enhance web development skills. [h1] 5 year plan? 5 year plan graduate cs major , earn great job enjoy. 

just small correction in order of method execution. need read , initialize heading , paragraphs first, followed writing in html file.

public static void main(string[] args) {     initialize(output_file);     readparagraphs(input_file);     writebio(title);     system.out.println("completed"); } 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -