Details
-
New Feature
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
Description
In File's some convenient methods like File#eachLine(), File#splitEachLine() and others, there is no way to specify the encoding for reading.
For example, there is no 'File#eachLine(String charSet, Closure c)' method.
Of cource, we can write:
new InputStreamReader(new FileInputStream(new File("file_to_read.txt")), charSet).eachLine { .. }
but this is not so groovy.
My proposal is, to add encoding() method to java.io.File as a GDK enhancement method, which can be used like:
new File(args[0]).encoding("utf-8").eachLine { println it }
As reference, if write it by EMC, the definition of method encoding is like:
File.metaClass.encoding = { cs -> new InputStreamReader(new FileInputStream(delegate), cs) }
GDK of java.io.InputStreamReader has equivalents each* methods, this is enough.