我有Room
类,这是在Hostel
类举行的ArrayList,我想此ArrayList写入一个文本文件中。什么是最有效的方法?写的ArrayList到文本文件
旅馆类
public class Hostel
{
private ArrayList <Room> rooms;
}
室类
abstract class Room
{
public Room(int newRoomNo, boolean newRoomEnSuite, int newRoomNights, String newRoomBooker)
{
roomNo = newRoomNo;
roomEnSuite = newRoomEnSuite;
roomBooking = "Booked";
roomNights = newRoomNights;
roomBooker = newRoomBooker;
}
}
请参阅http://docs.oracle.com/javase/1.4.2/docs/api/java/io/FileWriter.html – 2011-12-19 19:04:25
创建一个方法,将一个房间写入作为参数传递的文件。然后打开一个文件,使用'for'循环遍历数组列表并写入每个'Room'实例,然后关闭文件。如有疑问,请使用谷歌。 – 9000 2011-12-19 19:05:22