Consider a try-with-resources, if you're using Java 7.
try (BufferedWriter w = new BufferedWriter
(new OutputStreamWriter(
new FileOutputStream(outFile), "utf-8"))) {
w.write("Test string");
w.newLine();
} catch (IOException ex) {
ex.printStackTrace();
}
If your problem is the amount of code that would be inside the try block, consider factoring that code into a method.
try (BufferedWriter w = new BufferedWriter
(new OutputStreamWriter(
new FileOutputStream(outFile), "utf-8"))) {
writeEverythingINeed(w);
} catch (IOException ex) {
ex.printStackTrace();
}
Alternatively, you have no option but to enclose the remaining statements inside an if.
BufferedWriter w = null;
try { w = ... }
catch (FileNotFoundException | UnsupportedEncodingException e) {
System.out.println(e.getMessage());
}
if (w != null) {
w.write("Test string");
w.newLine();
}
Again, the block inside the if may be refactored into a method.