2个回答
展开全部
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了...
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.BufferedReader;
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();
}
}
}
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();
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询