import java.io.*; /** InputLab8 - Demo code for Input/Output */ public class InputLab8 { static InputStreamReader reader = new InputStreamReader(System.in); static BufferedReader console = new BufferedReader(reader); public static void readInput() { try { System.out.println("Your name?"); String name = console.readLine(); System.out.println("roll number?"); String roll = console.readLine(); System.out.println("department"); String dept=console.readLine(); System.out.println("date of birth"); String dob=console.readLine(); System.out.println("userid"); String user=console.readLine(); System.out.println("home page"); String home=console.readLine(); System.out.println("hostel"); String hostel=console.readLine(); System.out.println("room number"); String room=console.readLine(); String toStore="name:"+name; toStore+="\nRoll no:"+roll; toStore+="\nDept:"+dept; toStore+="\nDOB:"+dob; toStore+="\nUsername:"+user; toStore+="\nHomepage:"+home; toStore+="\nHostel:"+hostel; toStore+="\nRoom no:"+room; writeToFile(toStore); } catch(IOException ie) { System.out.println("IOException occured"); } } public static void writeToFile(String str) { try { FileWriter fw=new FileWriter("Sample.txt"); fw.write(str,0,str.length()); fw.close(); } catch(IOException ie) { System.out.println("Error in writing to file"); } } public static void main(String ars[]) { readInput(); } }