4 ms·
I keep wanting to like Java, but they insist on everything being done the hard way compared to C#. Sure, you want to provide a bunch of different readers, and
by AndrewDucker 9y ago
I keep wanting to like Java, but they insist on everything being done the hard way compared to C#.
Sure, you want to provide a bunch of different readers, and let people put them together however you want.
But compare the example there of using a BufferedReader in a loop to read in a file, and compare to the equivalent in C# - File.ReadLines (which gives you an IEnumerable<string>) or even File.ReadAllLines (which gives you a string[]). 99% of the time that's all you want, and yet Java makes you do the work yourself rather than just giving you a utility method.
- martinp 9y agoBad example. You can do this in Java 8: java.nio.file.Files.readAllLines(path) which returns List<String>.
- singularity2001 9y agoso they fix this one horribly convoluted use case, but most of the others are remaining?
- noobymatze 9y agoThere is a utility method `Files.readAllLines` [1] (even since Java 7) which gives you a List<String>. Since Java 8 there is even a lazy variant `Files.lines()` [2], which returns a Stream<String>. Though you gotta be a bit careful with that last one and be sure to close the underlying reader, as mentioned in the docs. I get your sentiment though. [1]: https://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#readAllLines(java.nio.file.Path,%20java.nio.charset.Charset) https://docs.oracle.com/javase/7/docs/api/java/nio/file/File... [2]: https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html#lines-java.nio.file.Path-java.nio.charset.Charset- https://docs.oracle.com/javase/8/docs/api/java/nio/file/File...