I want to overwrite in this file but I cannot. It just store one time. I want to store data every time I input in it.
int i = 0;
while (i != 1) {
int choice;
System.out.println("1-show employee");
System.out.println("2-add employee");
System.out.println("3-remove employee");
System.out.println(" Enter Your Choice ");
Scanner s = new Scanner(System.in);
choice = s.nextInt();
switch (choice) {
case 1:
String z = showEmployee();
System.out.println(z);
break;
case 2:
String em;
Scanner v = new Scanner(System.in);
em = v.nextLine();
addEmployee(em);
System.out.println("Employee added");
break;
default:
System.out.println("wrong ");
break;
}
System.out.println("Continue=0");
System.out.println("Exit=1");
i = s.nextInt();
}
}
public static void addEmployee(String n) throws FileNotFoundException, IOException {
DataOutputStream f1 = new DataOutputStream(new FileOutputStream("E:\\test.txt"));
f1.writeUTF(n);
f1.close();
}
public static String showEmployee() throws FileNotFoundException, IOException {
DataInputStream f1 = new DataInputStream(new FileInputStream("E:\\test.txt"));
return f1.readUTF();
}