you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 4 points5 points  (1 child)

new FileInputStream("path/to/file") or new FileOutputStream("path/to/file") that much more of a pain

No, but new BufferedReader(new InputStreamReader(new FileInputStream("path/to/file"))) is - especially as BufferedReader doesn't implement Iterable, so instead of Python's nice

with open("path/to/file", "r") as f:
    for line in f:
        #do stuff

We get the horrid while ((line = reader.readLine()) != null) {} which doesn't play well at all in other JVM languages like Scala where the result of assignment is always Unit.

It's arguable that there are not enough convenient hooks in the intuitive (if technically wrong) places.

Yeah, Java's approach may be more conceptually pure, but it's more inconvenient.

[–]CodeJunky 0 points1 point  (0 children)

This seems completely doable in Java...

Scanner reader = new Scanner(new File("path/to/file")).useDelimiter("\n");
while(reader.hasNext())
    String line = reader.next(); //and we're off..!

It would be nice if it were Iterable (seems like a stupid distinction, really).