Java FileReader

xqcjames 2011-03-28 04:38:55
package cs;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JOptionPane;


public class Rsmap {
public static void main(String[] args) {
try{
FileReader fr=new FileReader("d:\\student.txt");
BufferedReader br=new BufferedReader(fr);
String aline;

Map<String,String> map=new HashMap<String,String>();
while((aline=br.readLine())!=null){
String[] s=new String[2];
s=aline.split(" ");
map.put(s[0],s[1]);

}

String s1;
s1=JOptionPane.showInputDialog(null,"请输入要查询的号码:");
JOptionPane.showMessageDialog(null, "对应的名字是:"+map.get(s1));
System.out.println(map.get(s1));

fr.close();
br.close();

}catch(Exception e){
e.printStackTrace();
}

}

}

执行后报错:
java.io.FileNotFoundException: d:\student.txt (系统找不到指定的文件。)
...全文
77 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xqcwade 2011-09-03
  • 打赏
  • 举报
回复
这个很有意思
xqcjames 2011-03-28
  • 打赏
  • 举报
回复
问题已解决!!谢谢大家的回复了~~~
幽饮烛 2011-03-28
  • 打赏
  • 举报
回复
明显没有 d:\\student.txt 这个文件啊~~
singwhatiwanna 2011-03-28
  • 打赏
  • 举报
回复
那你d盘到底有没有student.txt呢
或者写成d:/student.txt

58,454

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧