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