Os:windows7 x64
Jdk:jdk-8u131-windows-x64
Ide:eclipse Oxygen Release (4.7.0)
Information:
Text file contents are read
Code
Package Jizuiku0;import Java.io.fileinputstream;import Java.io.filenotfoundexception;import java.io.IOException; Import Java.io.inputstreamreader;import java.io.linenumberreader;/* * @version V17.09 */public class Lnrdemo {//I use t here Hrows, the purpose is to easily read the code//However in the project you still need to use try. The catch handles the exception accordingly public static void main (string[] args) throws IOException, FileNotFoundException {String pathName = "Hello . txt "; String mycharset = "UTF-8";//Because Hello.txt uses the UTF-8 character set LineNumberReader LNR = new LineNumberReader (New InputStreamReader ( New FileInputStream (PathName), mycharset)); String line = null;while (lines = Lnr.readline ()) = null) {//Getlinenumber can get a good row number if (lnr.getlinenumber () = = 3) {//IF The line number is 3, then the line number that was originally 3 is changed to 10lnr.setlinenumber (10);} System.out.println (Lnr.getlinenumber () + ":" + Line);} Lnr.close ();}}
Result
Java is good, worth learning.
Learning resources: Itcast and Itheima Video library. If you have public resources, can share to me, with your resources to learn also can.
Blog post is to watch the video, into thinking written. It's good that the teacher speaks well. Blog bad, is to give the most bitter not serious.
JavaSE8 base LineNumberReader Set/getlinenumber set and get current line number