PrintWriter
gives more methods (println
), but the most important (and worrying) difference to be aware of is that it swallows exceptions.
You can call checkError
later on to see whether any errors have occurred, but typically you'd use PrintWriter
for things like writing to the console - or in "quick 'n dirty" apps where you don't want to be bothered by exceptions (and where long-term reliability isn't an issue).
I'm not sure why the "extra formatting abilities" and "don't swallow exceptions" aspects are bundled into the same class - formatting is obviously useful in many places where you don't want exceptions to be swallowed. It would be nice to see BufferedWriter
get the same abilities at some point...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…