Java RandomAccessFile .writeUTF (String str)
Syntax
RandomAccessFile.writeUTF(String str) has the following syntax.
public final void writeUTF(String str) throws IOException
Example
In the following code shows how to use RandomAccessFile.writeUTF(String str) method.
/* w w w . ja v a 2s .co m*/
import java.io.RandomAccessFile;
public class Main {
public static void main(String[] args) {
try {
String s = "Hello world from java2s.com";
RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw");
raf.writeUTF(s);
raf.seek(0);
System.out.println(raf.readUTF());
raf.seek(0);
raf.writeUTF("This is an example from java2s.com");
raf.seek(0);
System.out.println(raf.readUTF());
raf.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »