关于文本文件的读写 首先从文件读出一行,然后分解成2个token,在写入hashtable到文件结束,这样就得到一个id索引的hashtable可以方便使用了readline-->stringtokenizer-->hashtable 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 顺便给出例子package test;import java.io.*;import java.util.*;public class testfile { public static void main(String[] args) { String filename = "testfile.txt"; Hashtable h = new Hashtable(); try{ BufferedReader in = new BufferedReader(new FileReader(filename)); String str = in.readLine(); while (str != null) { StringTokenizer st = new StringTokenizer(str, "="); while (st.hasMoreTokens()) { String id = st.nextToken(); String name = st.nextToken(); h.put(id, name); } str = in.readLine(); } in.close(); } catch(IOException e) { e.printStackTrace(); } catch(Exception ee) { ee.printStackTrace(); } //test if get right String result = (String)h.get("1111"); if (result != null) { System.out.println("1111 = " + result); } }} java.util.Property类 很方便的 阿 笔误 java.util.Properties Properties property = new Properties();property.load(new FileInputStream(new File(filename)));property.getProperties("1111"); 呵呵 是不是很方便 java.util.ResourceBundle最直接了,用它...具体的看看国际化的东东... 很同意copyright(笨蛋白痴神经质) 不过我觉得不用建一个哈西表,就每次读入一行判断是否需要的id。是取出"="后面的,不是继续读。 直接readLine,然后使用String的split方法就可以获得了 求教JAVA(Eclipse)动态拓展数组 求一个在控制台(doc下)运行的加减计算器小程序 链表问题 执行时出错,请高手指教! JAVA程序怎么可以脱离开JVM执行呀? java初学者关于arraylist的问题 用JB8.0的问题,Boland公司的产品是这样的吗? 高分向送,简单问题 我从网上下载了mysql-connector-java-2.0.14,但是在jbuilder 7 下配置不了 那位大虾给讲一讲JDeveloper,小弟这里先谢过了! 关于文件的保存方式对用RandomAccessFile()读取问题的影响的问题: 毕业设计求助(更多分相送)!
package test;import java.io.*;
import java.util.*;public class testfile {
public static void main(String[] args) {
String filename = "testfile.txt";
Hashtable h = new Hashtable();
try{
BufferedReader in = new BufferedReader(new FileReader(filename));
String str = in.readLine();
while (str != null)
{
StringTokenizer st = new StringTokenizer(str, "=");
while (st.hasMoreTokens())
{
String id = st.nextToken();
String name = st.nextToken();
h.put(id, name);
}
str = in.readLine();
}
in.close();
}
catch(IOException e)
{
e.printStackTrace();
}
catch(Exception ee)
{
ee.printStackTrace();
}
//test if get right
String result = (String)h.get("1111");
if (result != null) {
System.out.println("1111 = " + result);
}
}
}
property.load(new FileInputStream(new File(filename)));
property.getProperties("1111"); 呵呵 是不是很方便
不过我觉得不用建一个哈西表,就每次读入一行判断是否需要的id。是取出"="后面的,不是继续读。