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