/**
 * @(#)RAFWriteDemo.java
 *
 *
 * @author 
 * @version 1.00 2008/1/23
 */
import java.io.*;

public class RAFWriteDemo {

    public static void main(String [] args)
    {
    	try	//try out the following code, if there is an error, then "catch" it below
    	{
    		RandomAccessFile file = new RandomAccessFile("myFile.txt", "rw");	//notice the "rw", which says we are opening the file for reading and for writing
	    	
	    	String str = "first words";
	    	String str2 = "second set of words";
	    	
	    	//writeUTF() first writes to file 2 bytes, which is the size of the string in bytes
	    	//THEN writeUTF() actually writes to file the string in bytes
	    	file.writeUTF(str);	
	    		
	    	file.writeUTF(str2);
	    	
	    	file.close();	//close the file when we are done
    	}
    	catch(IOException e)
    	{
    		System.out.println(e.toString());
    	}
    	
    }
    
}