显示到屏幕上。
BufferedReader br=new BufferedReader(new FileReader(filePath));
while ((String s = br.readLine()) != null) {
System.out.println(s + "\r\n");
}
////主要的代码应该差不多,你自己再修改一下就OK了...追问
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
public class printlnt {
public static void maid(String args[]){
File filePath = new File("D:\\AB.txt");
BufferedReader br=new BufferedReader(new FileReader(filePath));
while ((String s = br.readLine()) != null) {
System.out.println(s + "\r\n");
}
}
}这样在最后两行还是有报错的。
////这样就OK了,你再试试....
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class Printlnt {
public static void main(String args[]) throws IOException {
File filePath = new File("D:\\AB.txt");
BufferedReader br;
String s = null;
try {
br = new BufferedReader(new FileReader(filePath));
while ((s = br.readLine()) != null) {
System.out.println(s + "\r\n");
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
////你上面的程序中main方法,你写成了maid,这样能编译也是不能运行的...
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
public class printlnt {
public static void main(String args[]) throws Exception{
File filePath = new File("D:\\AB.txt");
BufferedReader br=new BufferedReader(new FileReader(filePath));
String s = br.readLine();
while ( s != null) {
System.out.println(s + "\r\n");
s = br.readLine();
}
}
}