Practical 11


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

JAVA Code :-

import java.lang.*;
import java.io.*;
public class pra11
{
    public static void main(String[] args)
    {
        System.out.println("\n-------Writing Data in File-------");
            try {
                   FileOutputStream fout = new FileOutputStream("a.txt");
                  String str = "Nmae : Ayush, Stream : IT Engineering, Sem : 5th Sem";
                  byte b[] = str.getBytes();
                  fout.write(b);
                  fout.close();
                  System.out.println("successful write.");
           }  
            catch (Exception e) {
                  System.out.println(e);
             }
            System.out.println("\n-------Retrive Data From File-------");
            try {
            FileInputStream fin = new FileInputStream("a.txt");
            int i = 0;
            while ((i = fin.read()) != -1) {
                System.out.print((char) i);
            }
            fin.close();
        }
            catch (Exception e) {
            System.out.println(e);
        }
    }
} 

Output:-





No comments:

Post a Comment

Programs

Home Aim:- Write a program to convert rupees to dollar. (60rupees=1 dollar). Aim:- Write a program that calculate percentage marks...