📄 find.java
字号:
package system;
import java.io.*;
import java.util.*;
public class Find {
public long numberTokenizer(String s) throws IOException {
StringTokenizer st = new StringTokenizer(s, " ");
return Integer.valueOf((st.nextToken())).longValue();
}
// 查找数据
public void findData(long find) throws IOException, NumberNotFoundException {
String s = "", findString = "";
long i;
DataMap dm = new DataMap();
BufferedReader in = new BufferedReader(new FileReader("d:\\data.txt"));
while ((s = in.readLine()) != null) {
i = numberTokenizer(s);
dm.put(i, s);
}
try {
if (dm.containsKey(String.valueOf(find).toString())) {
findString = dm.get(find);
System.out.println("学号" + find + "学生的资料是:");
System.out.println(findString);
} else
throw new NumberNotFoundException();
} catch (NumberNotFoundException e) {
System.out.println(find + " no found :(");
}
}
}
class NumberNotFoundException extends Exception {
/**
*
*/
private static final long serialVersionUID = 1L;
public NumberNotFoundException() {
System.out.println("您输入错误!");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -