Steve Rose is a very bad man. Vodka and Baileys is no drink for a man, but if (much against your will) you do drink it, you get very pissed indeed.
Anyway, we had a look at his code. He's fallen afowl of Java's laberynthine java.io. Now, I need a FileInputStream, an InputStreamReader and a BufferedReader to read a file, right? Or is that a FileReader and a BufferedReader? I've done this loads of times, and I still can't remember. It's hardly surprising that Steve can't work it all out. There really ought to be an openTheGoddamFileAlready() method somewhere...
Update: Here's how you do it in Python. Less is more.
Posted to Java by Simon Brunning at February 02, 2005 11:10 AMhttp://javaalmanac.com/ is invaluable for those sorts of things I find.
Just enough code to solve a clearly defined problem and no cruft.
But yes, Java does need a simple way of reading a file.
Posted by: Darren on February 2, 2005 01:12 PMThanks for the pointer Darren. You java types are nice people, not like RPGers who are just in it for the money, or Python people who just get you blind drunk!
Posted by: Steve on February 2, 2005 02:03 PMThe java.io libraries are annoyingly granular, but they provide a level of control over your input stream you can't easily get in other languages, and are surprisingly fast for what they do. Python is beautiful as long as all you want is what it provides, but beyond that you start getting frustrated. This is why Pythonistas drink so much. Analogies to women come to mind here.
Most serious Java code doesn't work at that level on a regular basis. Instead, you make a FileUtil class, and put a bunch of static methods in it to handle your various file readers. String[] lines = FileUtil.readLines(new File("whatever.txt")); is pretty concise. Let any exceptions fly up the stack somewhere.
Why doesn't Sun give us some standard file readers built in, or File methods to get the contents? Because they HATE US. That's my theory, anyway.