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

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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.