package test; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.LineNumberReader; import java.math.BigDecimal; import java.nio.channels.NonReadableChannelException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; import privateclass.MyBufferedReader; public class Main { private static final String space_operator = " "; private static final double pi = Math.PI; private static final String LINE_SEPARATOR = System.getProperty("line.separator"); public static void main(String[] args) throws Exception { FileReader fileReader = new FileReader("Myheat.txt"); LineNumberReader lineNumberReader = new LineNumberReader(fileReader); String line = null; while((line = lineNumberReader.readLine()) != null) { System.out.println(lineNumberReader.getLineNumber() + ":" + line); } lineNumberReader.close(); } }
原文:https://www.cnblogs.com/WINDZLY/p/11788788.html