Thursday , 4 June 2020
Home » Class 12 » Sample Programs on Operations on Text Files for ISC Computer Science

Sample Programs on Operations on Text Files for ISC Computer Science

Below are the sample codes of the operations performed on a text file. These operations include:

  1. Creating and Writing to a Text File
  2. Reading and Displaying from a Text File
  3. Copying the records of a Text File into another Text File
  4. Deleting a record from a File
  5. Inserting a record into a File
  6. Deleting a file completely
  7. Renaming an old file to a new file name
  8. Editing/Replacing a record in a File
  9. Sorting the records stored in the file in alphabetical order
  10. Searching for a record in a file
  11. Merging 2 files into a single file

Codes of all the above operations have been written in a single class, each one written in a separate method.

Note: All the file names you enter for the above operations when you are asked must be valid and it must be present in the same directory (except for the operation of creating a file) where your programs are saved.

When you are asked for a filename, then give the complete filename along with it’s extension like “Sample.txt”

If you want to print a copy of the below code, then the PDF file of the codes can be downloaded from here: Programming codes for Operations on Files [ISC Computer Science]

Programming Code: 

/** @author
 *  @Topic : Operations on Text Files 
 *  @Program Type : BlueJ Program – Java */

class OperationOnFile
    static BufferedReader b=new BufferedReader (new InputStreamReader(;

    /* Creating and Writing to a File */

    void create(String fileName, int n)throws IOException
        FileWriter fw=new FileWriter(fileName,false);
        BufferedWriter bw=new BufferedWriter(fw);
        PrintWriter pw=new PrintWriter(bw);
        String name;
        for(int i=0; i0)
        System.out.println("\nThe file currently contains the following:");
        System.out.println("The Names after sorting Alphabetically are: ");
        for(int i=0; i

Check Also

Infix Postfix Prefix Conversion – Correct Method (ISC Computer Science)

In this video we discuss about the correct way of converting an Infix Expression to Postfix and Prefix.

Leave a Reply

Your email address will not be published. Required fields are marked *