Our prof only showed us one example about how to use FileIO，now she wants us to write one. I'm so confused about how to set it up. I knew the general concepts, like how to use fileReader and BufferedReader and close them, but I don't know how to put these pieces together.
Here are all the instructions she gave us:
FileIO.java must contain the following public static method:
• readCharacter() method.
This method takes as input a filename as a String parameter, and returns a new Character, using the constructor defined in the Character class.
The readCharacter method must use a FileReader and a BufferedReader in order to open the file specified by the filename. Make sure to catch FileNotFoundException and IOException when reading from the file. If either exception is raised, print an appropriate error message and return null.
You can assume that the files that readCharacter receives as input have all the same format: they contain 4 lines, with the following information
- Name of the character
- Attack value
- Maximum health
- Number of wins so far in the battle game
Examples of such files are the player.txt and the monster.txt files are provided with the assign- ment. Use the readLine() method of the BufferedReader to retrieve the content of the file. Use the information retrieved to create and return the appropriate object of type Character.
We need to read two files, one called player, the information it contains are: Odin10.030.00
Another one called Fenrir12.030.03
Thanks for helping me out!
Recently Asked Questions
- In this case, why the concentration of CH3COOH is 1-x instead of 1-2x?
- What are the genetic and fossil evidence for this model and trace the migration of modern Homo sapiens across the globe? "Considering the modern human
- Using lims to evaluate the folloing limits where possible. a) lim x→2 f(x)^g(x) b) lim x→1 g(x)/f(x)+3 c) lim x→1 g(f(x)-3)