I am having trouble outputting a string to the console window using Eclipse 3.2. My code is as follows:
package test;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
public class Test {
public static void main(String args[]) {
System.out.println("Hello world!");
BufferedWriter bw;
try {
bw = new BufferedWriter(new OutputStreamWriter(System.out,"ISO-8859-1"));
}
catch (UnsupportedEncodingException e) {
System.out.println("Default encoding.");
bw = new BufferedWriter(new OutputStreamWriter(System.out));
}
// Try to print a test string
try{
bw.write("Hello World!");
}
catch (IOException e) {
System.err.println(e.getMessage());
}
}
}
The System.out.println() statement works as expected, but not the write() method of the BufferedWriter class. I would be grateful if someone could point me in the right direction.
Thank you,
Olle