RandomAccessFile: writeUTF(String str)
import java.io.IOException;
import java.io.RandomAccessFile;
public class Main {
public static void main(String[] args) throws IOException {
RandomAccessFile raf = new RandomAccessFile("employee.dat", "rw");
raf.writeUTF("J");
raf.writeUTF("S");
raf.writeDouble(4.0);
raf.seek(0L);
String fname = raf.readUTF();
String lname = raf.readUTF();
double salary = raf.readDouble();
System.out.println("First name = " + fname);
System.out.println("Last name = " + lname);
System.out.println("Salary = " + salary);
raf.close();
}
}
Home
Java Book
File Stream
Java Book
File Stream
RandomAccessFile:
- RandomAccessFile
- new RandomAccessFile(String fileName, String mode)
- RandomAccessFile: close()
- RandomAccessFile: getChannel()
- RandomAccessFile: getFilePointer()
- RandomAccessFile: length()
- RandomAccessFile: read(byte[] b)
- RandomAccessFile: readBoolean()
- RandomAccessFile: readByte()
- RandomAccessFile: readChar()
- RandomAccessFile: readDouble()
- RandomAccessFile: readInt()
- RandomAccessFile: readLine()
- RandomAccessFile: seek(long pos)
- RandomAccessFile: write(byte[] b)
- RandomAccessFile: writeBoolean(boolean v)
- RandomAccessFile: writeBytes(String s)
- RandomAccessFile: writeChars(String s)
- RandomAccessFile: writeInt(int v)
- RandomAccessFile: writeUTF(String str)