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
Advertisement
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();
    }
}

Advertisement

Related Tags for Java create table in html file:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: September 22, 2006

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com