直接上代码?
package com.kaka.test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
public class demo{
public static void main(String[] args){
File file=new File("D:\\WEAVER\\ecology\\WEB-INF\\prop\\weaver.properties");
BufferedReader reader=null;
String temp=null;
int line=1;
try{
reader=new BufferedReader(new FileReader(file));
while((temp=reader.readLine())!=null){
System.out.println("line"+line+":"+temp);
line++;
}
}
catch(Exception e){
e.printStackTrace();
}
finally{
if(reader!=null){
try{
reader.close();
}
catch(Exception e){
e.printStackTrace();
}
}
}
}
}
运行结果如下:
?