Random Access Files

J

justin_davies_2002

I am new to java and need some help.

I am using random access files in java and want to create a new blank
file, every time i call my file handler constructor. The problem is if
i pass the same name more than once and the file is already created it
will not give me an empty file, it appends new content to the end of
the existing file.

Can you help me so when i pass a file name more than once a new blank
file is created every time.

The code i am using is below, any help would be great.

Thank you



// file handler constructor
public FileHandler(String filename)
{
// set current position to zero
currentposition = 0;

// set last position to zero
lastposition = 0;

// Open or create the random access file
try
{
myFile = new RandomAccessFile(filename, "rw");
}
catch(IOException ex)
{
System.out.print("Exception ERROR: " + ex);
System.exit(0);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top