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

📄 dicservice.java

📁 一个用java编写的字典。使用的是数组查询来实现单词的查找。附带单词文档。有1万多个单词课查询。可以设置server和port.
💻 JAVA
字号:
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.StringTokenizer;


public class DicService {
	private String[] myindex;
	private String[] mydic;
	public DicService(){
		indexDicserv();
	}
	//store the dictionary from files into array
	public void indexDicserv(){
		Scanner inputStream = null;
		StringBuffer contentIndex = new StringBuffer();
		try {
			inputStream = new Scanner(new FileInputStream("myindex.txt"));
		} catch (FileNotFoundException e) {
			System.out.println("Error opening the file");
			System.exit(0);
		}
		while (inputStream.hasNextLine()) {
			String line = inputStream.nextLine();
			contentIndex.append(line+" ");
		}
		StringTokenizer tk = new StringTokenizer(contentIndex.toString());
		myindex = new String[tk.countTokens()];
		mydic = new String[tk.countTokens()];
		for(int i = 0; i < myindex.length/2; i++){
			myindex[i] = tk.nextToken();
			tk.nextToken();
		}
		try {
			inputStream = new Scanner(new FileInputStream("mydic.txt"));
		} catch (FileNotFoundException e) {
			System.out.println("Error opening the file");
			System.exit(0);
		}
		int num = 0;
		while (inputStream.hasNextLine()) {
			String line = inputStream.nextLine();
			StringTokenizer tko= new StringTokenizer(line,"-");
			tko.nextToken();
		    mydic[num] = tko.nextToken();
		    num++;
		}
		inputStream.close();
	}
	
	public String translate(String word){
		System.out.print("word \"" + word + "\" to be searched");
		int index = -1;
		for(int i = 0; i < myindex.length/2; i++){
			if(myindex[i].equalsIgnoreCase(word)){
				index = i;
				break;
			}
		}
		System.out.println(index);
		String description = "";
		if(index == -1){
			description = "Can not found in the dictionary!";
			System.out.println("  Fail!");
		}
		else{
			description = mydic[index];
			System.out.println("  Success!");
		}
		return description;
	}
	
}

⌨️ 快捷键说明

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