我有一个任务是创建一个计算演员培根数的程序。这是我给定的 ActorMovieTist.txt 文件的内容,该文件应该在我的程序中读取。Adolf Hitler Der Ewige Jude 1940 Angelina Jolie Mr. & Mrs. Smith 2005Anne Hathaway Valentine's Day 2010Benedict Cumberbatch The Hobbit: An unexpected Journey 2012Benedict Cumberbatch Black Mass 2015Brad Pitt Mr. & Mrs. Smith 2005Brad Pitt Sleepers 1996Brad Pitt Ocean's Thirteen 2007Brad Pitt Beyond All Boundaries 2009Brad Pitt Se7en 1995Christian Bale The Fighter 2010Curt Bois Der Ewige Jude 1940Curt Bois The Great Sinner 1949Denzel Washington 2 Guns 2013Denzel Washington The Equalizer 2014David Struffolino The Equalizer 2014David Struffolino Knight and Day 2010Hugh Jackman Flushed Away 2006Hugh Jackman X Men First Class 2011Ian McKellen The Hobbit: An unexpected Journey 2012Julia Roberts Valentine's Day 2010Julia Roberts Flatliners 1990Kate Winslet Flushed Away 2006Kenneth Tobey The Great Sinner 1949Kenneth Tobey Hero at Large 1980Kevin Bacon Sleepers 1996Kevin Bacon Beyond All Boundaries 2009Kevin Bacon Flatliners 1990Kevin Bacon Patriots Day 2016Kevin Bacon Black Mass 2015Kevin Bacon X Men First Class 2011Kevin Bacon Hero at Large 1980Kevin Spacey Se7en 1995Kevin Spacey Patriots Day 2016Kevin Spacey Austin Powers in Goldmember 2002Mark Wahlberg 2 Guns 2013Mark Wahlberg Patriots Day 2016Mark Wahlberg The Fighter 2010Matt Damon Ocean's Thirteen 2007Tom Cruise Austin Powers in Goldmember 2002这是我的程序,它应该使用 Scanner 来读取这个文件并将每一行保存为 ArrayList 的一个元素,但它没有。我在最后打印了 ArrayList 的大小,但我的程序一直说 0。我做错了什么?
1 回答
人到中年有点甜
TA贡献1895条经验 获得超7个赞
当你这样做时,你正在覆盖你的输入文件
Formatter output = new Formatter("ActorMovieList.txt");
如果文件存在,那么它将被截断为零大小;否则,将创建一个新文件
由于您似乎没有使用此output
对象,只需删除此行并重新创建您的输入文件。
添加回答
举报
0/150
提交
取消