JavaSE8 base LineNumberReader Set/getlinenumber set and get current line number

Source: Internet
Author: User



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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.