Reading and Writing to a .txt file in Java

后端 未结 4 548
[愿得一人]
[愿得一人] 2020-12-22 04:00

Here is my prompt for the assignment: Your program needs to read the information from a text file instead of using a scanner to read from command line. Your program also ne

4条回答
  •  旧时难觅i
    2020-12-22 04:38

    You can use the Scanner class the same way you use it to read the names of the file. All you have to do is define how you will structure your file. For example, separate your info with a special character i.e: "," and use that as a token to identify the different fields in your file for the name, grades, etc. (see the Pattern and Scanner APIs to use REGEX's for this)

    You might want to create a Student class and map the needed fields to that class, add them to a List and iterate over that much easier.

    As for writing to a text file, you are already doing it, check FileWriter to see how to add a new line and that will be it. Good Luck!

提交回复
热议问题