LineNumberReader is a buffered character-input stream that keeps track of line numbers. You can use LineNumberReader to read line by line any InputStream convertible object.
By default, UTF-8 encoding will be used to construct the reader but you can give and optional argument with charset name to change it.
1 Examples
Copy
<script> var src = Ax.io.File.createTempFile(); src.write("Hello World!"); var lnr = new Ax.io.LineNumberReader(src, "ISO-8859-1"); console.log("Reading " + src); for (var line of lnr) { console.log(Ax.text.String.format("%4d", lnr.getLineNumber()) + ": " + line); } </script>
Reading /etc/hosts
1: ##
2: # Host Database
3: #
4: # localhost is used to configure the loopback interface
5: # when the system is booting. Do not change this entry.
6: ##
7: 127.0.0.1 localhost
8: 255.255.255.255 broadcasthost
9: ::1 localhost
10:
11: 192.168.10.100 titan