Practical 11 : Create a class called Student. Write a student manager program to manipulate the student information from files by using FileInputStream and FileOutputStream
Program :
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class practical11 {
public static void main(String[] args) {
System.out.println("-------Writing Data in File-------");
try {
FileOutputStream fout = new FileOutputStream("stdinfo.txt");
String str = "Nmae : Pruthviraj, Stream : INFORMATION TECHNOLOGY, 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("-------Retrive Data From File-------");
try {
FileInputStream fin = new FileInputStream("stdinfo.txt");
int i = 0;
while ((i = fin.read()) != -1) {
System.out.print((char) i);
}
fin.close();
} catch (Exception e) {
System.out.println(e);
}
}
}
Output:
Comments
Post a Comment