Coders Packet

File Handling in Java: Changing from lowercase to uppercase

By Subhashree Dutta

This project is all about taking a line of text as input and store it in a file and read the text from the file and convert the entire text into uppercase and display the result.

Hey coders!! Hope everyone is doing well.

We know that Java is one of the most popular programming language. It supports a large number of functionalities, one of such is File Handling in Java.

File handling in Java implies reading from and writing data to a file. The File class from the package, allows us to work with different formats of files. In order to use the File class, you need to create an object of the class and specify the filename or directory name. The io in package stands for Input and Output.

The syntax for creating an object and use the file as a class:

import;                     //Import File class

File obj = new File("filename.txt");                    //Specifying the file name


In this program we will see that 3 process occurs:

  1. Taking a line of text as an input and store it in a file.
  2. Read the text from the file.
  3. Convert the entire text into uppercase and display the result.

Firstly we import the File class as “import;” and then specify the file name as “File f= new File(“data”). We are taking a string as an input which will be in the lowercase and finally the output will be in uppercase.

We know,

 ASCII values of alphabets: A – Z = 65 to 90, a – z = 97 to 122 

Basic trick: If a character in an index is in lower case, then subtract 32 to convert it in upper case, else add 32 to convert it in lower case



Download Complete Code


No comments yet