/**
* Write contents to txt file using "RandomAccessFile "
*
*/
String filepath = "E:\\wwwroot\\tmp\\testRandomAccreeFile.txt";
RandomAccessFile f = new RandomAccessFile(filepath,"rw");
f.seek(7 * 7 - 2);
String toWrite = "Helloo";
// not work, it will output one white space after one char.
//f.writeChars( toWrite );
// not work, it will output one white space and a new line
// before toWrite after writing
// f.writeUTF( toWrite );
// This is the right solution
f.write(toWrite.getBytes());
f.close();
没有评论:
发表评论