Create a class called Student. Write a student manager program to manipulate the student information from files by using FileInputStream and FileOutputStream

Create a class called Student. Write a student manager program to manipulate the student information from files by using FileInputStream and FileOutputStream title

Create a class called Student. Write a student manager program to manipulate the student information from files by using FileInputStream and FileOutputStream

Hello friends i hope you like my previous post, in today’s post we are going discuss about, “Create a class called Student. Write a student manager program to manipulate the student information from files by using FileInputStream and FileOutputStream”

(note : programs based on gtu syllabus)

So you have to  Create a class called Student. Write a student manager program to manipulate the student information from files by using FileInputStream and FileOutputStream 

so now let’s discuss the logic, how you can implement it

Implementation

First define the variables in main class

  •  String   
    • str = “Name : Sachin, Stream : Computer Engineering, Sem : 5th Sem”;
  •  byte 
    • b[]
  •  Integer 
    • i = 0;

So you have to write program that read student’s information from File OR write student’s information to file (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 “FileOutputStream” class is used
  • for reading data from file “FileInputStream” class is used

WRITING DATA TO FILE

first you have to write data so you have to make object of “FileOutputStream” class in example we taken object name as “fout”

you have to pass file name with extension of file during creating object of “FileOutputStream” class

Example:

you opened file successfully now you need some data to write in file for that let’s store some demo data in String variable  str = “Name : Sachin, Stream : Computer Engineering, Sem : 5th Sem”; 

now you have data but it is in String form you have to convert it to sequence of bytes for that you have to use one more variable type of byte b[] = str.getBytes();

than pass variable “b” in to write() method of FileOutputStream AND close the object “fout” of FileOutputStream using close() method

here’s the logic for writing date into file is completed

Example:

READING DATA FROM FILE

Now let’s discuss about reading data from file, for reading data from file you have to make use of “FileInputStream” class

So first create object of “FileInputStream” class in example we taken object name as “fin”

you have to pass file name with extension of file during creating object of “FileInputStream” class

Example:

Now take one variable ” i ” for get position of characters stored in file AND for checking the end of file while reading data from file

for reading data we are going to use “WHILE LOOP” and it runs up-to end of file

in “WHILE LOOP” condition we are going to initialize variable ” ” with position  of character stored in file using read() method of “FileInputStream” and inside while loop we are going to print that character (Note: use System.out.print() instead of  System.out.println() for printing )

after end of “WHILE LOOP” close the object of “FileInputStream”

so here’s reading data from file is also completed

Example:

so here’s our programming logic discussion is completed for “Create a class called Student. Write a student manager program to manipulate the student information from files by using FileInputStream and FileOutputStream”

Check Out other post – WRITE AN INTERACTIVE PROGRAM TO PRINT A DIAMOND SHAPE

so here your program’s solution, check program below the post for reference

these are the java basic programs based on gtu syllabus

Program :

OUTPUT :

Create a class called Student. Write a student manager program to manipulate the student information from files by using FileInputStream and FileOutputStream

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

You May Also Like

About the Author: TheCoder

Leave a Reply

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