I have a .dat file with many lines. I need to overwrite a certain line. Let's just say I have to overwrite the 5th line of the dat file. How would I set the RandomAccessFile to overwrite at line 5 (or any line in general)? (P.S.: each line has 10 characters, if that helps)

Recommended Answers

I remember a discussion about this on Daniweb before. You might want to do a search for it. But I'm pretty sure the only way to do what you want is to read the file, delete it, and write what you want the file to be back to the same …

Jump to Post

All 2 Replies

you can replace the data without deleting and creating new, read your data into a string buffer then call replace();

StringBuffer sb = yourData;
sb.replace(int start, int end, String str)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.