I wish to write name along with date and time onto a file for this i use an arraylist.But when i write it onto file..a single name along with date appears twice; It is related somewhere to my implying StandardOpenOption.Append because when I don't it prints date and values once but does overwrite my previous values.][1]
//created method to write date and name onto file
public void standardRoom()
{
try {
Path p=Paths.get("test/standardRoom.text");
if(Files.notExists(p))
{
Files.createFile(p);
}
System.out.println("Enter Name");
String name=sc.next();
List<String>stdrooms=new ArrayList<>();
date = d.toString();
stdrooms.add(date);
stdrooms.add(name);
System.out.println("Standard Room booked");
Iterator<String>bookings=stdrooms.iterator();
while(bookings.hasNext())
{
String s=bookings.next();
//Files.write(p, stdrooms);
Files.write(p, stdrooms,StandardOpenOption.APPEND);
}
} catch (IOException e) {
}
}
}