RandomAccessFile Concept

hi friends,using the RandomAccessFile class concept to how can i fix the file size?
[97 byte] By [MCA134a] at [2007-11-27 1:43:32]
# 1

hi,

your question is too vague...

anyway, this is a random access file example :

try {

File f = new File("filename");

RandomAccessFile raf = new RandomAccessFile(f, "rw");

// Read a character

char ch = raf.readChar();

// Seek to end of file

raf.seek(f.length());

// Append to the end

raf.writeChars("aString");

raf.close();

} catch (IOException e) {

e.printStackTrace();

}

java_2006a at 2007-7-12 1:01:35 > top of Java-index,Java Essentials,Java Programming...
# 2
What do you mean "fix the file size"? As in you want to spay or neuter it? ;-)
masijade.a at 2007-7-12 1:01:35 > top of Java-index,Java Essentials,Java Programming...
# 3
hi,i want to roll over the file, that means i want to fix the file size (ex:10MB)
MCA134a at 2007-7-12 1:01:35 > top of Java-index,Java Essentials,Java Programming...
# 4

> hi,

>

> i want to roll over the file, that means i want to

> fix the file size (ex:10MB)

This make even less sense than the first question.

When you write to the end of a RandomAccessFile it will automatically increase that files size. You do not have to (in any way shape or form) manually set the files size. If you want to artificially make the file larger than it has to be, write some null bytes to the end of it.

Now, once again, what do you mean by "fix the file size".

masijade.a at 2007-7-12 1:01:36 > top of Java-index,Java Essentials,Java Programming...
# 5
when i said "fix" the filesize, what i meant was fix the size limit for the filesize i.e. 10 MB. When the file size reaches 10 MB, any more write attempts should automatically overwrite the file. Think you can help me with that?
MCA134a at 2007-7-12 1:01:36 > top of Java-index,Java Essentials,Java Programming...
# 6

You need to do it programatically. i.e. programtically. There is no set method. With each write you need to check the size, and if it will be too large, then you need to shift everything to the front (which will take a while if you do it this way), or better, close the file, rename it, and open a new file (At least this is the way that most self rotating logging algorithms do it.)

masijade.a at 2007-7-12 1:01:36 > top of Java-index,Java Essentials,Java Programming...
# 7
Thank you sir
MCA134a at 2007-7-12 1:01:36 > top of Java-index,Java Essentials,Java Programming...