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 (系统找不到指定的文件。)
------解决方案--------------------
这个很有意思