You are on page 1of 2

//SOUVIK & SOUMODIP

A program to accept five names from the user and store it in a file in the
hard disk, 'names.txt'.

import java.io.*;
public class FileInput
{
public static String fileName=("names.txt");
public static InputStreamReader isr=new
InputStreamReader(System.in);
public static BufferedReader stdin=new BufferedReader(isr);
public static void main()throws IOException
{
FileWriter fw=new FileWriter(fileName,true);
BufferedWriter bw=new BufferedWriter(fw);
PrintWriter outFile=new PrintWriter(bw);
for(int i=0;i<5;i++)
{
System.out.print("Enter Name :");
String name=stdin.readLine();
outFile.println(name);
}
outFile.close();
}
}
SAMPLE OUTPUT:

Enter Name :Souvik


Enter Name :Soumodip
Enter Name :Granthik
Enter Name :Manish
Enter Name :Saurav

You might also like