NCRE训练二

package com.fei.ncre;

import java.io.RandomAccessFile;

/**
 * 该程序的功能是将本程序代码打印输出
 */
public class Java_2 {
	
	// *********Found********
	public static void main(String args[]) throws Exception {
		long filePoint = 0;
		String s;
		
		// 文件路径需要在包名前加上src/,不然会报java.io.FileNotFoundException:文件找不到异常
		RandomAccessFile file = new RandomAccessFile("src/com/fei/ncre/Java_2.java", "r");
		
		// 获得文件的长度,以便下面计算偏移量
		long fileLength = file.length();
		while (filePoint < fileLength) {
			// *********Found********
			s = file.readLine();
			System.out.println(s);

			// getFilePointer方法返回从文件开始的偏移量,以字节为单位,进行下一个读或写操作发生
			filePoint = file.getFilePointer();
		}
		file.close();
	}
	
}

原文地址:https://www.cnblogs.com/zxfei/p/11123809.html