Java按行读txt文档代码记录
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class TestSohu {
/**
* @param args
*/
public static void main(String[] args) {
try {
StringBuffer sb= new StringBuffer("");
FileReader reader = new FileReader("E://sohuAddress.txt");
BufferedReader br = new BufferedReader(reader);
String str = null;
while((str = br.readLine()) != null) {
sb.append(str+"/n");
System.out.println(str);
}
br.close();
reader.close();
}
catch(FileNotFoundException e) {
e.printStackTrace();
}
catch(IOException e) {
e.printStackTrace();
}
}
}