Home Tutorial Java Core Files Java create table in html file

 
 

Java create table in html file
Posted on: September 22, 2006 at 12:00 AM
In this section, you will learn how to create table in html file.

Java create table in html file

In this section, you will learn how to create table in html file.

In the previous section, you have seen different operations on text file like creating a file, deleting a file, copying a file etc. Here we are going to perform operation on a html file.

You can see in the given example, we have created an instance of PrintWriter class and used FileWriter as an argument. Now we have used the html table tag to create a table in html file. In tables we have created a rows and columns to display the numbers and their squares from numbers 1 to 20.

Here is the code:

import java.io.*; import java.text.*;

public class CreateHTMLTable {
     public static void main(String[] a) throws IOException {
                PrintWriter pw = new PrintWriter(new FileWriter("C:/test.html"));
                pw.println("<TABLE BORDER><TR><TH>Number<TH>Square of Number</TR>");
                for (int i = 1; i <= 20; i++) {
                       int square = i * i;
                       pw.println("<TR><TD>" + i + "<TD>" + square);
                }
                pw.println("</TABLE>");
                pw.close();
    }
}

Related Tags for Java create table in html file:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.