« Home | Program to read excel sheet Using Java program » | Redirect output, error report to files instead of ... » | Assertions in java » | Program to copy a folder in java » | java.net.BindException: Address already in use: JV... » | java.lang.UnsupportedClassVersionError: » | Merge Sort » | Insertion Sort » | Selection Sort » | Program to Implement Quick Sort » 

Wednesday, September 12, 2007 

RandomAccessFiles in Java

import java.io.File;
import java.io.RandomAccessFile;
import java.io.IOException;


public class RandomAccessFileExample {

private static void doAccess() {

try {

File file = new File("Test5Example.txt");

RandomAccessFile raf = new RandomAccessFile(file, "rw");

// Read a character

byte ch = raf.readByte();

System.out.println("Read first character of file: " + (char)ch);

System.out.println("Read full line: " + raf.readLine());

// Seek to the end of file

raf.seek(file.length());

// Append to the end of the file

raf.writeChars("for appending to the input file");

raf.writeBytes("this will also written into the output file");

raf.close();

}

catch (IOException e) {

System.out.println("IOException");

e.printStackTrace();

}

}

public static void main(String[] args) {

doAccess();

}

Hi Phanindra..
u were in IBM?
in past

Hi Phanindra..
u were in IBM?
in past

Post a Comment

About me

  • I'm phanindra
  • From Hyderabad, Andhra Pradesh, India
  • An Alumini of JNTU Hyd into happening IT industry...
My profile

Visitors
Bloggeries Blog Directory BlogRankings.com singapore blog directory blog search directory
Google
 
Web conceptoftheday.blospot.com