数组列表写入文本文件来 [英] Writing arraylist to textfile

查看:118
本文介绍了数组列表写入文本文件来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类客房这是在课堂上举行的ArrayList 旅馆,我还想写此ArrayList到文本文件。什么是这样做的最有效的方法?

旅馆类

 公共类旅馆
{
    私人的ArrayList<客房>室;
}

室等级

 抽象类房
{公众间(INT newRoomNo,布尔newRoomEnSuite,INT newRoomNights,弦乐newRoomBooker)
    {
        roomNo = newRoomNo;
        roomEnSuite = newRoomEnSuite;
        roomBooking =预订
        roomNights = newRoomNights;
        roomBooker = newRoomBooker;
    }
}


解决方案

只有一行的commons-io的

  FileUtils.writeLines(新文件(路径),清单);

I have an arraylist of class Room which is held in class Hostel, i would like to write this arraylist to a text file. What is the most efficient method of doing so?

Hostel Class

public class Hostel
{
    private ArrayList < Room > rooms;
}

Room Class

abstract class Room
{

public Room(int newRoomNo, boolean newRoomEnSuite, int newRoomNights, String        newRoomBooker)
    {
        roomNo = newRoomNo;
        roomEnSuite = newRoomEnSuite;
        roomBooking = "Booked";
        roomNights = newRoomNights;
        roomBooker = newRoomBooker;
    }
}

解决方案

A one-liner from commons-io

FileUtils.writeLines(new File(path), list);

这篇关于数组列表写入文本文件来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆