我们将ArrayList写入文件时遇到问题。 该文件仍为空。我们的代码中没有发现任何错误。 请帮助我们,我们的截止日期是几个小时......
public void rapportAssortiment(String winkelNaam) throws Exception
{
ArrayList <Artikel> assortiment = db.rapportAssortiment(winkelNaam);
PrintWriter outputStream = null;
try
{
outputStream = new PrintWriter(new FileOutputStream("RapportAssortiment.txt",true));
outputStream.println("Rapport van het assortiment van winkel " + winkelNaam);
outputStream.println("Artikelnummer" + ";" + "Artikelnaam" + ";" + "Prijs" + ";" + "Aantal bonuspunten" + ";" + "Aantal bonuspunten nodig" + ";" + "Minimum aantal stuks" + ";" + "Minimum bedrag" + ";" );
for(int i = 0; i< assortiment.size(); i++)
{
outputStream.println(assortiment.get(i).getArtikelNr() + ";" + assortiment.get(i).getArtikelNaam() + ";" + assortiment.get(i).getPrijs() + ";" + assortiment.get(i).getAantPunten() + ";" + assortiment.get(i).getAantPuntenNodig() + ";" + assortiment.get(i).getMinAantStuks() + ";" + assortiment.get(i).getMinBedrag() );
}
}
catch(Exception exc)
{
System.out.println("Rapport trekken mislukt.");
}
}
答案 0 :(得分:2)
完成写作后
outputStream.flush();
outputStream.close();