Overwriting the text in the file

Hi
I am writing a simple java program in which i am facing some difficulty while writing the text in the file.
Aim of the program is to add some debug message in the empty catch block.

I am able to add the message but the text in the file are overwriting. I used RandomAccessFile and when i find the position i used writeBytes. But it overwrites the text in files (below the catch block..3-4 lines).

Can someone suggest how can i add text without overwriting using RandomAccessFile .

Since you are writing out textual content, you should use a Writer instead of dealing with raw bytes and the like. What exactly is your requirement? If you don't need to edit the file at a random location, RandomAccessFile isn't even required. If the text is overwriting the original text, it means you are not properly aligning your file pointer.

Look into the methods getFilePointer() for saving the previous write location and seek() to move to that location. Without a working compilable code, helping you out will be difficult.

Thanks,
Actually I need to add debug message in the empty catch block from the list of the files present in the particular directory.
so i have to add the message at any random location according to the condition.
Can i use FileWriter obj ?How can i add message in the middle of the file using FileWriter obj?
Here is my whole code.I am passing directory name as a comman line argument.As of now i have hard coded for the Log message in the condition.Please copy this code in a new file to get the good visibility.Program is running.You can run and place some java files with empty catch blocks in the directory.Thanks...
Thanks

Thanks,
Actually I need to add debug message in the empty catch block from the list of the files present in the particular directory.
so i have to add the message at any random location according to the condition.
Can i use FileWriter obj ?How can i add message in the middle of the file using FileWriter obj?
Here is my whole code.I am passing directory name as a comman line argument.As of now i have hard coded for the Log message in the condition.Please copy this code in a new file to get the good visibility.Program is running.You can run and place some java files with empty catch blocks in the directory.Thanks...
Thanks

The problem you are trying to solve here has already been addressed by AOP i.e. addressing cross cutting concerns. Read this.

Sifting through that big code would be quite a herculean task; I would advice you to use an IDE like Eclipse/Netbeans for debugging your application. Also I hope you realize that the logic you so painstakingly wrote would break as soon as someone decides to format the code in a different way?