怎么用JAVA程序从一个TXT文件中按指定行读取内容?
3个回答
展开全部
基本结构如下,楼主可参考一下:
try{
pwd=System.getProperty("user.dir");//获取当前目录
FileReader fr = new FileReader(pwd + "\\1.txt");
BufferedReader br = new BufferedReader(fr);
String Line = br.readLine();
while (Line != null) {
System.out.println(Line);
Line = br.readLine();
}
br.close();
fr.close();
}catch(IOException ex){}
try{
pwd=System.getProperty("user.dir");//获取当前目录
FileReader fr = new FileReader(pwd + "\\1.txt");
BufferedReader br = new BufferedReader(fr);
String Line = br.readLine();
while (Line != null) {
System.out.println(Line);
Line = br.readLine();
}
br.close();
fr.close();
}catch(IOException ex){}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询