标签:基础 exce adl alt lease lips exception 博文 logs
os :windows7 x64
jdk:jdk-8u131-windows-x64
ide:Eclipse Oxygen Release (4.7.0)
information:
被读取文本文件内容

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 {
// 我在这里使用 throws,目的是为了方便地阅读代码
// 然而 在做项目中 还是需要使用try..catch对异常做出相应的处理
public static void main(String[] args) throws IOException, FileNotFoundException {
String pathName = "hello.txt";
String myCharset = "UTF-8";// 因为hello.txt使用UTF-8字符集
LineNumberReader lnr = new LineNumberReader(new InputStreamReader(new FileInputStream(pathName), myCharset));
String line = null;
while ((line = lnr.readLine()) != null) {
// getLineNumber 可得到行号挺好用的
if (lnr.getLineNumber() == 3) {
// 如果行号为3了,那么将原本是3的行号改为10
lnr.setLineNumber(10);
}
System.out.println(lnr.getLineNumber() + ":" + line);
}
lnr.close();
}
}
result:
Java优秀,值得学习。
学习资源:itcast和itheima视频库。如果您有公开的资源,可以分享给我的话,用您的资源学习也可以。
博文是观看视频后,融入思考写成的。博文好,是老师讲得好。博文坏,是 给最苦 没认真。
JavaSE8基础 LineNumberReader set/getLineNumber 设置与得到当前行号
标签:基础 exce adl alt lease lips exception 博文 logs
原文地址:http://www.cnblogs.com/jizuiku/p/7586545.html