public class TestLine {
static int lineNumber = 0;
public static void main(String[] args) {
try {
BufferedReader reader = new BufferedReader(new FileReader("test.txt"));
while(reader.ready()) {
lineNumber = lineNumber + 1;
String line = reader.readLine();
int columnNumber = line.length();
System.out.println("This is line " + lineNumber + " , " + columnNumber + " columns.");
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
java解析txt文件
最新推荐文章于 2024-04-08 14:33:27 发布