在搜索了几个小时的答案后,我决定在这里询问,因为我发现的解决方案无效。
我有一个简单的GUI来注册一个人的名字/姓氏和出生日期。输入值之后,数据将列在JList中。现在,我想将JList中的数据保存到一个Txt文件中。但是我找不到从JList中获取数据的方法。
public void save(){
try(BufferedWriter bw = new BufferedWriter(new FileWriter("jlist.txt")))
{
/* Here should be the part, where I get the data from the JList */
bw.write(person.getNachname() + " ; " + person.getVorname() + " ; " + person.getDate() + "\n");
} catch (Exception speichern) {
speichern.printStackTrace();
}
}
稍后,我要获取创建的Txt文件并将其加载回同一JList中。
也许有更好的方法可以做到这一点,但我还没有发现。
一些提示会有所帮助:)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句