RandomAccessFile Example

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
public class RandomAccessFileDemo1 
{
	String str1=null;
	String str2=null;
	public void write1()
	{
	try
	{
	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	System.out.println("Enter employee no ");
	str1=br.readLine();
	System.out.println("Enter employee name ");
	str2=br.readLine();
	RandomAccessFile file=new RandomAccessFile("emp.txt","rw");
	file.seek(file.length());
	file.writeBytes("\n"+str1+":"+str2);
	file.close();
	}
	catch(Exception e)
	{
	System.out.println("error in reading text"+e);
	}
	}
	public void read1()
	{
	try
	{
	RandomAccessFile file=new RandomAccessFile("emp.txt","rw");
	while(file.getFilePointer()

Download

Input and Output Stream in Java

Example FileOutputStream
Example FileInputStream
DataInput and Output Example
Object Serialization
Object Deserialization
Object Externalizable Example
Example java.io.File class
RandomAccessFile Example


Write your Comment

Name :
Email Id : [ We will not publish your email id ]
Your Comment : [ Maximum 200 chars ]
Enter Security code