Monday, January 13, 2014

Read txt file and then put it into html file

Read txt file and then put it into html file

import java.awt.Desktop;
import java.io.*;

public class ShowGeneratedHtml {

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(
            new FileReader("D:\\New folder\\11.txt"));

        File f = new File("d:\\temp\\source.htm");
        BufferedWriter bw = new BufferedWriter(new FileWriter(f));
        bw.write("<html>");
        bw.write("<body>");
        bw.write("<h1>ShowGeneratedHtml source</h1>");
        bw.write("<textarea cols=75 rows=20>");

        String line;
        while ((line=br.readLine())!=null) {
            bw.write(line);
            bw.newLine();
        }

        bw.write("</text" + "area>");
        bw.write("</body>");
        bw.write("</html>");

        br.close();
        bw.close();

        Desktop.getDesktop().browse(f.toURI());
    }
}

No comments:

Post a Comment