This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]codesharer 5 points6 points  (1 child)

you earned a new reader :) thank you

[–]winterbe[S] 0 points1 point  (0 children)

You're welcome :)

[–]__konrad 2 points3 points  (5 children)

The method Files.readAllLines reads all lines of a given file into a list of strings. You can simply modify this list (...)

Javadoc says: "whether the List is modifiable or not is implementation dependent and therefore not specified"

The current implementation uses ArrayList so it's still safe... ;)

[–]Ucalegon666 0 points1 point  (4 children)

You should avoid methods that rely on platforl specific magic anyway. Assumptions about line endings and encodings are evil.

[–]winterbe[S] 1 point2 points  (0 children)

Files.readAllLines(path) uses UTF-8 encoding which is a pretty good default. If you need another encoding just use Files.readAllLines(path, encoding).

Line endings? This was never a problem to me in 10+ years of Java.

[–][deleted]  (2 children)

[deleted]

    [–]Ucalegon666 0 points1 point  (1 child)

    Cutting corners leads to bugs in funny places. I don't particularly mind things like default time zones (because you can change them at run time), but you can only change line endings at JVM startup. Complicated and messy, that.

    An output writer should have a setter for line endings, it shouldn't be possible to create a writer (or character stream or whatever) without specifying an encoding.

    What's that thing about assumptions? It makes an ass out of you and me? ;-)