Input.java
资源名称:mcl.tar.gz [点击查看]
上传用户:kingseaxu
上传日期:2009-01-01
资源大小:49k
文件大小:2k
源码类别:
3G开发
开发平台:
Java
- import java.util.*;
- import java.io.*;
- import java.lang.*;
- class Input {
- int MAX_LENGTH = 1024;
- int MAX_LINE = 1000;
- String token[];
- String value[];
- int token_num;
- public Input(String filename) {
- BufferedReader is;
- String inputLine;
- StringTokenizer st;
- token_num = 0;
- token = new String[MAX_LINE];
- value = new String[MAX_LINE];
- try {
- is = new BufferedReader(new FileReader(filename));
- while ((inputLine = is.readLine()) != null) {
- for (int i = 0; i < inputLine.length(); i++)
- if (inputLine.charAt(i) == '#') /* comment */
- inputLine = inputLine.substring(0, i);
- if (inputLine.length() == 0) /* blank line */
- continue;
- inputLine = inputLine.trim();
- if (inputLine.length() > 0) {
- st = new StringTokenizer(inputLine, "t");
- token[token_num] = st.nextToken().trim();
- value[token_num] = st.nextToken().trim();
- token_num++;
- }
- }
- is.close();
- } catch (Exception e) {
- System.err.println(e);
- }
- }
- public String getParameter(String name) {
- int i;
- for (i = 0; i < token_num; i++) {
- if (token[i].equalsIgnoreCase(name))
- return (value[i]);
- }
- return null;
- }
- public void setParameter(String name, String result) {
- int i;
- for (i = 0; i < token_num; i++) {
- if (token[i].equalsIgnoreCase(name))
- value[i] = new String(result);
- }
- }
- }