Advertisement
filip-krupa

addToDatabase

Dec 13th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.72 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3. class FileSave
  4. {
  5.  public static void main(String ar[])
  6.  {
  7.  
  8.   Scanner sc=new Scanner(System.in);
  9.  
  10.   System.out.println("Enter the ID:");
  11.   String id=sc.nextLine();
  12.   System.out.println("Enter the first name:");
  13.   String fn=sc.nextLine();
  14.   System.out.println("Enter the last name:");
  15.   String ln=sc.nextLine();
  16.   System.out.println("Enter the salary:");
  17.   String sl=sc.nextLine();
  18.   System.out.println("Enter the location:");
  19.   String lc=sc.nextLine();
  20.  
  21.   try
  22.   {
  23.    File f=new File("Database.txt");
  24.    PrintWriter pw=new PrintWriter(new FileOutputStream(f,true));
  25.    pw.append("\n"+id+","+fn+","+ln+","+sl+","+lc);
  26.    pw.close();
  27.   }
  28.   catch(Exception e){}  
  29.  }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement