Java write to file. Using a loop

后端 未结 6 1686
不知归路
不知归路 2021-01-25 00:53

I have a simple application that yet would trash a text file (it\'s just practice) I\'m only 3 days with Java yet. Problem is there are no errors until you run the program then

6条回答
  •  后悔当初
    2021-01-25 01:47

    When you close the file as in the following line

     file.close()
    

    it means you are done working with the file.

    In your case you close the file in the loop which means the next iteration will throw an exception.

    Move the above mentioned code out of the loop.

提交回复
热议问题