I have this class currently, however when I try to write the data to the text file, it asks me which object I want to write. If I enter the instance name of the object, only the data stored in that object is printed. If I enter another instance name, the previous data is replaced with the new data.
public class WriteHotelData
{
public static void main ( String [] args)
{
}
public void writeHotelData(ArrayList <Room> rooms)
{
for (int i = 0; i > rooms.size(); i++)
{
System.out.println( i + "Room information: " + rooms.get(i));
}
}
void getRoomData(Room rooms) throws IOException
{
Writer out = new OutputStreamWriter(new FileOutputStream("hotelData.txt"));
try
{
out.write
(rooms.roomNumber
+ " "
+ rooms.hasEnSuite
+ " "
+ rooms.bookingName
+ " "
+ rooms.bookingNights
+ " "
+ rooms.isBooked);
}
finally
{
out.close();
}
}
}
What I want is when I run the Write Data class, all objects stored in an arraylist are printed on separate lines in a text file, thanks!