List of usage examples for java.io RandomAccessFile readUTF
public final String readUTF() throws IOException
From source file:Main.java
public static void main(String[] args) { try {/*from w w w. ja v a2 s . co m*/ 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(); } }
From source file:Main.java
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);// www. jav a 2s . c o m 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(); }
From source file:Main.java
public static void main(String[] args) { try {/* w w w . j a v a2 s . c o m*/ RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw"); raf.writeUTF("Hello World from java2s.com"); // set the file pointer at 0 position raf.seek(0); System.out.println(raf.readUTF()); // set the file pointer at 0 position raf.seek(0); raf.writeUTF("This is from java2s.com"); // set the file pointer at 0 position raf.seek(0); // print the string System.out.println(raf.readUTF()); raf.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { try {//from w ww . j a v a 2 s . c o m RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw"); raf.writeUTF("java2s.com"); // set the file pointer at 0 position raf.seek(0); // read and print the contents of the file System.out.println(raf.readUTF()); // close the strea and release resources raf.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { try {//from w w w . j a va 2 s. co m RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw"); raf.writeUTF("Hello World from java2s.com"); // set the file pointer at 0 position raf.seek(0); // print the string System.out.println(raf.readUTF()); // print current length System.out.println(raf.length()); // set the file length to 30 raf.setLength(30); System.out.println(raf.length()); raf.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { try {//from w w w . java 2 s. c om RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw"); raf.writeUTF("Hello World from java2s.com"); // set the file pointer at 0 position raf.seek(0); // print the string System.out.println(raf.readUTF()); // set the file pointer at 5 position raf.seek(5); // write something in the file raf.writeUTF("This is an example from java2s.com"); // set the file pointer at 0 position raf.seek(0); System.out.println(raf.readUTF()); raf.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { try {//from w w w . ja v a 2s . c om RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw"); raf.writeUTF("java2s.com Hello World"); // set the file pointer at 0 position raf.seek(0); // read and print the contents of the file System.out.println(raf.readUTF()); // return the channel of the file System.out.println(raf.getChannel()); // close the strea and release resources raf.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { try {//from w w w . j a v a 2 s . c om RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw"); raf.writeUTF("java2s.com Hello World"); // set the file pointer at 0 position raf.seek(0); // read and print the contents of the file System.out.println(raf.readUTF()); // return the file descriptor of the stream System.out.println(raf.getFD()); // close the strea and release resources raf.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { try {//from w w w .j a va2 s . co m RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw"); raf.writeUTF("Hello World from java2s.com"); // set the file pointer at 0 position raf.seek(0); // print the string System.out.println(raf.readUTF()); // set the file pointer at 0 position raf.seek(0); // attempt to skip 10 bytes System.out.println(raf.skipBytes(10)); System.out.println(raf.readLine()); // set the file pointer to position 8 raf.seek(8); // attempt to skip 10 more bytes System.out.println(raf.skipBytes(10)); raf.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { try {// w w w . jav a2 s . c o m RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw"); // write something in the file raf.writeUTF("java2s.com Hello World"); // set the file pointer at 0 position raf.seek(0); // read and print the contents of the file System.out.println(raf.readUTF()); // print the length of the file System.out.println(raf.length()); // write something more in the file raf.writeUTF("This is an example"); // print the length of the file System.out.println(raf.length()); raf.close(); } catch (IOException ex) { ex.printStackTrace(); } }