83.RandomAccessfile in java
//randomaccessfile
import java.io.*;
import java.util.*;
class randomaccessfile
{
public static void main(String[] args) {
try
{
Scanner obj = new Scanner(System.in);
int n, ch;
long len;
RandomAccessFile raf = new RandomAccessFile("File.txt","r");
len = raf.length();
System.out.print("Enter last character to Display : ");
n = obj.nextInt();
if (n > len) {
raf.seek(0);
}
else
{
raf.seek(len - 0);
}
raf.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
OUTPUT:
Comments
Post a Comment