RANDOM ACCESS FILE CONCEPT

Ads
 

RANDOM ACCESS FILE CONCEPT

In a random access file, first write the alphabets a,b, c, d till z. Read the file in reverse order and print it on screen.

View Answers

June 13, 2012 at 5:06 PM

The given code uses RandomAccessFile file to write the alphabets from A to Z into the textfile. After storing the alphabets into the file, it then read the file in reverse order and display it on console.

import java.io.*;

    class  RandomAccessFileExample
    {
        public static void main(String[] args) 
        {
            try{
            File f=new File("c:/alphabet.txt");

                RandomAccessFile randomFile=new RandomAccessFile(f,"rw");
                for(int i=65;i<=90;i++){
                   randomFile.writeBytes(Character.toString((char)i));
                }
                 randomFile.close();
                RandomAccessFile raf = new RandomAccessFile(f, "r");
        long position = raf.length();
        while (position > 0) {
          position -= 1;
          raf.seek(position);
          byte b = raf.readByte();
          System.out.print((char) b);
        }
            }
            catch(Exception e){}
                }
    }

Ads









Related Tutorials/Questions & Answers:
RANDOM ACCESS FILE CONCEPT
RANDOM ACCESS FILE CONCEPT  In a random access file, first write the alphabets a,b, c, d till z. Read the file in reverse order and print it on screen
RANDOM ACCESS FILE CONCEPT
RANDOM ACCESS FILE CONCEPT  Write a program that stores the names of four employees in an array of strings. Store the contents of the array in an alphabetical order in a file and display it back on console. Do not use
Advertisements
RANDOM ACCESS FILE CONCEPT
RANDOM ACCESS FILE CONCEPT  Write a program to use a File object and print even numbers from two to ten. Then using RandomAccessFile write numbers from 1 to 5. Then using seek () print only the last 3 digits
RANDOM ACCESS FILE CONCEPT
RANDOM ACCESS FILE CONCEPT  Write a program to write the details of an employee to a file. Details such as year of joining, department code, employee name and salary should be included. You must use RandomAccessFile
Random Access File.
Random Access File.  Explain Random Access File
Random Access File class
Random Access File class  Write a short note on Random Access File class.   Please visit the following link: Java Random Access File
ModuleNotFoundError: No module named 'random-access-file-reader'
ModuleNotFoundError: No module named 'random-access-file-reader'  Hi...: No module named 'random-access-file-reader' How to remove the ModuleNotFoundError: No module named 'random-access-file-reader' error? Thanks  
Using a Random Access File in Java
RandAccessFile Enter File name : Filterfile.txt Write... the characters from a file using the readByte( ) method...;= in.readLine();   File file = new File(str
FILE CONCEPT
FILE CONCEPT  Prompt the user to enter the name of a text file to search for. If the name does not end in a .txt extension, display an error message. Search for this file in the current directory. If the file does not exist print
FILE HANDLING CONCEPT
FILE HANDLING CONCEPT   Write a program that reads input from the console in the form of a string. When the user enters a word called end, the program should stop reading from the console and print out the values that have been
FILE HANDLING CONCEPT
FILE HANDLING CONCEPT   Write a program that reads input from the console in the form of a string. When the user enters a word called end, the program should stop reading from the console and print out the values that have been
FILE HANDLING CONCEPT
FILE HANDLING CONCEPT  Prompt the user to enter the name of a text file to search for. If the name does not end in a .txt extension, display an error message. Search for this file in the current directory. If the file does
FILE HANDLING CONCEPT
FILE HANDLING CONCEPT  Write a program to read and write the details of an employee like year of joining, Department code, salary using some byte stream classes
Upload file to MS Access
Upload file to MS Access  Iam beginner and need to upload file to msaccess using jsp . Iam using netbeans platform. Kindly explain do I need to mention Attachment format in the table
ls: cannot access >: No such file or directory
ls: cannot access >: No such file or directory  import java.io.BufferedReader; import java.io.InputStreamReader; public class Example...: cannot access >: No such file or directory error is displayed .No f.txt
How to use random access file
How to use random access file In this section, you will learn the use... is used for both reading and writing files. A random access file treats...() method- It closes the random access file stream. writeBytes( ) method
access
access   This is Nitha Sriram i am having a problem that, i am having a combo box in the JSP page when i select an item from that i am calling the onchange function. In javascript i am getting the value now i want to pass
Random classes
Random classes  Hello... What is Random class? What's the purpose
Random classes
Random classes  Hello... What is Random class? What's the purpose
Random classes
Random classes  Hello... What is Random class? What's the purpose
What is HBase?
. It is highly useful when random access and writing of data are needed. HBase...-time access to large data sets for both read and write functionalities. HBase... very quick access to the queried information. How does HBase Work? HBase
How to Access MS Access in jar.
How to Access MS Access in jar.  how do i access my Ms-Access file placed in the same jar file where my application code/class file r present??? Want... this ... i m able to access a Ms-access via JDBC but cant find the file wen
IO concept
file to another and deletes the old file.   Hi Friend, Try...[] args) throws Exception { File f1=new File("C:/data.txt"); File f2=new File("D:/data.txt"); BufferedReader br=new BufferedReader(new
access into radio button
access into radio button  access the four fields of database called access,access file and stored in radio button.please help
How to access the image file from project folder itself while writing to pdf using itext?
How to access the image file from project folder itself while writing to pdf using itext?  I am writing a pdf using itext where i add a image in the beginning of the document. When i use image = Image.getInstance("C
getting random number in java
access to random class in java Created the object of Random class like - Random...getting random number in java  getting random number in java Hi everyone, i am trying to get a random number in a particular range. for example
how to retreive values from MS Access Database based on the values entered in textbox values in jsp file
how to retreive values from MS Access Database based on the values entered... in MS Access Database. the table structure is Sno JobName ProgramName Problem... a jsp file which contains a textbox, name issuedescription. when user types
MS access
MS access  how do i access my Ms-Access file placed in the same jar file where my application code/class file r present??? Want to access it via Code. Can anyone help me ? Please give reply urgent...   give me reply
random number
random number  Sir could u please send me the code registration form of roseindia.net with image varification
random numbers
random numbers  hi.. i am creating a website and on feedback form to authenticate user i want to generate a random number on label.if user types that number correctly in textbox then he is allowed to submit feedback otherwise
Random Creation of password
Random Creation of password  Dear Sir I have created a form with some... has my back end,....My database is Ms Access...my problem is that i am not able to generate a random password and insert into database... Please help me out

Ads