Hello
I am trying to write to a text log file for my world of zuul game. I have created a Class Logger to write into the file, here is the code:
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
public class Logger
{
private BufferedWriter out;
public Logger() throws IOException
{
//
fw = new FileWriter("logfile.txt");
//
bw = new BufferedWriter(fw);
}
public void logToFile(String input) throws IOException
{
this.input = input;
bw.write("User Input: " + input + "\n");
}
public void closeStream()
{
bw.close();
}
}
in the main Game class, I have added this bit to write into the file:
public void play()
{
printWelcome();
// Enter the main command loop. Here we repeatedly read commands and
// execute them until the game is over.
boolean finished = false;
while (! finished) {
Command command = parser.getCommand();
String input = command.getCommandWord() + command.getSecondWord();
logger.logToFile(input); //i get the error in here!
finished = processCommand(command);
}
logger.closeStream();
System.out.println("Thank you for playing. Good bye.");
}
and when compiling i got this error: unreported exception java.io.exception must be caught or declared to be thrown.
Not sure what it means! any help would be much appreciated!
mumaga 0 Light Poster
bguild 163 Posting Whiz
mumaga 0 Light Poster
Taywin 312 Posting Virtuoso
tux4life 2,072 Postaholic
mumaga 0 Light Poster
mumaga 0 Light Poster
Taywin 312 Posting Virtuoso
mumaga 0 Light Poster
Taywin 312 Posting Virtuoso
mumaga 0 Light Poster
Taywin 312 Posting Virtuoso
mumaga 0 Light Poster
Taywin 312 Posting Virtuoso
mumaga 0 Light Poster
Taywin 312 Posting Virtuoso
mumaga 0 Light Poster
Taywin 312 Posting Virtuoso
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.