
Refine the student manager program to manipulate the student information from files by using the Buffered Reader and Buffered Writer
Hello friends i hope you like my previous post, in today’s post we are going discuss about, “Refine the student manager program to manipulate the student information from files by using the Buffered Reader and Buffered Writer”
(note : programs based on gtu syllabus)
So you have to Refine the student manager program to manipulate the student information from files by using the Buffered Reader and Buffered Writer
so now let’s discuss the logic, how you can implement it
Implementation
- First import header files which are necessary for program
- BufferedReader
- BufferedWriter
- FileReader
- FileWriter
- Now define the variables in main class
- Integer
- i = 0;
- Integer
So you have to write program that Take input from file and check character by character if character is in lower case than convert in upper case or if character in upper case convert in to lower case (Note: file can be of any extension Ex: “.txt” )
So here first you have to write some student’s information to file, for that you have to make use of File Handling classes of java
- for writing data into file “FileWriter” AND “BufferedWriter” class is used
- for reading data from file “FileReader” AND “BufferedReader“class is used
First file contains any “text” you have to scan all text from first file character by character convert characters case and store in second file
you have to use “DO WHILE LOOP” cause you have to take all the characters from file and convert in opposite character case
READING DATA FROM FILE
Now let’s discuss about reading data from file, for Reading data from you have to create object of “BufferedReader” class inside that pass “FileName” using “FileReader” class
Example:
1 |
BufferedReader bufRead = new BufferedReader(new FileReader("stdinfo.txt")); |
Inside “DO WHILE LOOP” in every iteration of loop you have to initialize one character in variable ” ” i ” using “read()” method of “BufferedReader”
if variable ” i ” is not equal to -1 then check character is in Upper case or Lower case make sure use type casting cause we are initializing character in integer variable
if character in lower case than convert into upper case or character in Upper case than convert into Lower case and than store into new file using “write()” method of “BufferedWriter”
if character not in Upper case nor in Lower case than write as it is in new file using “write()” method of “BufferedWriter”
perform this operation while variable ” i ” is not equal to -1
example:
1 2 3 4 5 6 7 8 9 10 11 12 |
do { i = bufRead.read(); if (i != -1) { if (Character.isUpperCase((char) i)) { bufWrite.write(Character.toLowerCase((char) i)); } else { bufWrite.write((char) i); } } } while (i != -1); bufRead.close(); bufWrite.close(); |
so here’s our programming logic discussion is completed for “Refine the student manager program to manipulate the student information from files by using the Buffered Reader and Buffered Writer”
Check Out other post – Create a class called Student. Write a student manager program to manipulate the student information from files by using FileInputStream and FileOutputStream
so here your program’s solution, check program below the post for reference
these are the java basic programs based on gtu syllabus
Program :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; public class Student { public static void main(String[] argv) throws Exception { BufferedReader bufRead = new BufferedReader(new FileReader("stdinfo.txt")); BufferedWriter bufWrite = new BufferedWriter(new FileWriter("newstdinfo.txt")); int i; do { i = bufRead.read(); if (i != -1) { if (Character.isUpperCase((char) i)) { bufWrite.write(Character.toLowerCase((char) i)); } else { bufWrite.write((char) i); } } } while (i != -1); bufRead.close(); bufWrite.close(); } } |
OUTPUT :
stdinfo.txt
newstdinfo.txt
Program As per GTU Syllabus
if you like the the way of explanation tell us in comment section you can also write the queries about this program we are defiantly going reply
share this post with your college friends so everyone can get benefit of it good bye friends see you in next post happy coding