Java RandomAccessFile.write(int b)
Syntax
RandomAccessFile.write(int b) has the following syntax.
public void write(int b) throws IOException
Example
In the following code shows how to use RandomAccessFile.write(int b) method.
// w ww. java 2 s. c om
import java.io.*;
public class Main {
public static void main(String[] args) {
try {
int b1 = 15;
int b2 = 20;
RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw");
raf.write(b1);
// set the file pointer at 0 position
raf.seek(0);
System.out.println(raf.readByte());
raf.write(b2);
raf.seek(1);
System.out.println(raf.readByte());
raf.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »