find.java

来自「上次小组练习做的一个学生信息管理小系统 控制台的」· Java 代码 · 共 49 行

JAVA
49
字号
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 + =
减小字号Ctrl + -
显示快捷键?