Java Reference
In-Depth Information
import java.io.*;
public class CreateFileDemo
{
public static void main(String [] args)
{
try
{
FileWriter file = new FileWriter(“scores.html”);
BufferedWriter buffer = new BufferedWriter(file);
PrintWriter out = new PrintWriter(buffer);
out.println(“<html>\n\t<body>”);
out.println(“\t<table border=\”1\”>\n\t\t<tr>”);
out.println(“\t\t<td>Home:</td>\n\t\t<td>
Denver Broncos</td>\n\t\t<td>27</td>”);
out.println(“\t\t</tr>\n\t\t<tr>”);
out.println(“\t\t<td>Visitor:</td>\n\t\t<td>
Oakland Raiders</td>\n\t\t<td>24</td>”);
out.println(“\t\t</tr>\n\t</table>”);
out.println(“\t</body>\n</html>”);
out.close();
buffer.close();
file.close();
}catch(IOException e)
{
e.printStackTrace();
}
}
}
The RandomAccessFile Class
The upcoming RandomAccessDemo program uses a RandomAccessFile
object to view and modify the scores.html file created from the Create-
FileDemo program. The RandomAccessFile class has two constructors:
public RandomAccessFile(File file, String mode).
The File parameter
represents the file to be accessed.
public RandomAccessFile(String name, String mode). The name
parameter represents the name of the file to be accessed.
Both RandomAccessFile constructors contain a String parameter called
mode to represent how the file is to be used. The possible values of the mode
parameter are:
Search WWH ::




Custom Search