
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author bal
 */
public class HTMLDatenAusDatei {
 public static void main(String[] args) throws IOException {        
        StringBuilder html = new StringBuilder();
        html.append("<html>\n");
        html.append("<body>\n");
        html.append("Hallo Welt!\n");
        html.append("<table border=1 align=\"center\">\n");

        String fileDaten="test.txt";
     try {
         FileReader fr = new FileReader(fileDaten);
         BufferedReader buff = new BufferedReader(fr);
         String aktZeile="";
         while((aktZeile=buff.readLine())!=null) {             
           String[] spalten = aktZeile.split(";");
            html.append("<tr>\n");
            html.append("<td>" + spalten[0] + "</td><td>" + spalten[1] + "</td><td>" + spalten[2] + "</td>\n");
            html.append("</tr>\n");
         }
     } catch (FileNotFoundException ex) {
         System.out.println("Error: Datei "+fileDaten+" nicht lesbar");
     }
        html.append("</table>\n");
        html.append("</body>\n");
        html.append("</html>\n");
        System.out.println(html.toString());

        // Datei schreiben
        String filename = "test.html";
        boolean append = false;
        try {
            FileWriter file = new FileWriter(filename, append);
            BufferedWriter buff = new BufferedWriter(file);
            PrintWriter out = new PrintWriter(buff);
            out.println(html.toString());
            out.flush();
            out.close();
        } catch (IOException e) {
            System.out.println("Error:" + e);
        }
    }
    
}
