0

There is a text file like this:

abcd 
1234

and the code I am using :

RandomAccessFile file = null;       
  try {
     file = new RandomAccessFile("C:\\Users\\z36137zz\\Desktop\\test.txt", "rw");
     file.writeBytes("edcba\n");
     file.close();
 } catch (FileNotFoundException e) {
     e.printStackTrace();
 } catch (IOException e) {
     e.printStackTrace();
 }

And I want to change the first line to "edcba", I used the RandomAccessFile Class, but If I write "edcba", it will cover "1" of the second line. So what should I do?

Tejas Kale
  • 415
  • 8
  • 18
huashui
  • 1,758
  • 2
  • 16
  • 24

0 Answers0