import java.io.BufferedReader;import java.io.File;import java.io.FileReader;import java.io.IOException;publicclassFileLine{publicstaticvoid main (String args[])throws IOException {
File a =newFile("E:\\年少有为.txt");//Creates a new File instance if(a.exists()){//Tests whether the file or directory denoted by this abstract pathname exists.
System.out.println("文本:"+ a.getName()+" 存在");}else{
System.out.println("文本:"+ a.getName()+"不存在");}
FileReader fr =newFileReader("E:\\年少有为.txt");//Creates a new FileReader
BufferedReader br =newBufferedReader(fr);//Reads text from buffering characters so as to provide for the efficient reading of characters
String s = null;int i =0;while((s = br.readLine())!= null){//Reads a line of text.
i++;
System.out.println("第 "+ i +" 行内容为:"+ s);//A String containing the contents of the line
System.out.println("第 "+ i +" 行有 "+ s.length()+"个字节");//Returns the length of the file }
System.out.println("文本一共有 "+ i +" 行");}}