一个IO流的问题 文本文件中有10条数据,请编写程序读取第4行的信息 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 try { BufferedReader in = new BufferedReader(new FileReader("F:\\my.txt")); String str; int row = 0; while ((str = in.readLine()) != null) { row ++; if(row == 4){ System.out.println(str);// 这里是第四行 } } in.close(); } catch (IOException e) { } 楼上说得没错,最好在输出数据后 break; 掉,好像没有必须再继续下去了。 public String getLineData(String filePath, int lineNum) { BufferedReader in = new BufferedReader(new FileReader(filePath)); String str = null; int count = 0; while ((str = in.readLine()) != null) { count++; if(count == lineNum){ break; } } in.close(); return str;} java中textfield 怎么隐藏光标 HashMap中put方法JDK源码 有一处不懂为什么这么写 java 单引号 双引号的区别 最新版eclipse工具如何建立一个窗口 JAVA中的正则表达式怎么用? sql 中的in 查询问题,帮我看看! 怎样用java得到硬盘得序列号,谢谢 求助 小程序? 我编的简单的画图程序,显示总不正常。。(好心人请进) 如何修改JOptionPane的输出信息框的按钮的字体? SWT中setenabled(false)在哪里把字体颜色设成灰色的 请教一个有关JAVA连接数据库后取值的问题(付代码)
BufferedReader in = new BufferedReader(new FileReader("F:\\my.txt"));
String str;
int row = 0;
while ((str = in.readLine()) != null) {
row ++;
if(row == 4){
System.out.println(str);// 这里是第四行
}
}
in.close();
} catch (IOException e) {
}
BufferedReader in = new BufferedReader(new FileReader(filePath));
String str = null;
int count = 0;
while ((str = in.readLine()) != null) {
count++;
if(count == lineNum){
break;
}
}
in.close();
return str;
}