⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subjectfromcfg.java

📁 java编写的桌面考试系统.含所有源码.
💻 JAVA
字号:
package exam.dao;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;

public class SubjectFromCfg {
	private String[] items;
	private String[] paperName;
	private File subjectCfg;
	private int count;

	public SubjectFromCfg() {
		this.items = new String[4];
		this.paperName = new String[4];
		this.subjectCfg = new File("subject.cfg");
		this.count = 0;
		readFromCfg(subjectCfg);
	}

	@SuppressWarnings("unchecked")
	private void readFromCfg(File subjectCfg) {
		Properties p = new Properties();
		FileInputStream fis = null;

		try {
			fis = new FileInputStream(subjectCfg);
			p.load(fis);

			Set allKeys = p.keySet();
			Iterator it = allKeys.iterator();
			while (it.hasNext()) {
				String key = (String) it.next();
				if (items.length == count)
					extendData();
				items[count] = key;
				paperName[count++] = p.getProperty(key);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (fis != null) {
				try {
					fis.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}

	private void extendData() {
		String[] tempItems = new String[items.length + 1];
		String[] tempFileName = new String[paperName.length + 1];
		System.arraycopy(items, 0, tempItems, 0, items.length);
		System.arraycopy(paperName, 0, tempFileName, 0, paperName.length);
		items = tempItems;
		paperName = tempFileName;
		System.gc();
	}

	public String[] getItems() {
		return items;
	}

	public String[] getFileName() {
		return paperName;
	}

	public String getFileName(String subject) {
		for (int i = 0; i < items.length; i++) {
			if (subject.equals(items[i]))
				return paperName[i];
		}
		return null;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -