ben
Posts: 57
Nickname: loftty
Registered: Oct, 2002
|
|
Re: text files
|
Posted: Nov 7, 2002 3:13 AM
|
|
hello again ramu i have sent you my code i hope you can see what i am trying to achive i have sent the text from the file and put it though a string tokenizer then i have put the text into hash table with a key value. then i want to be able to read in any word from the text file or any two words so i want to be able to though the hash table and somehow be able to do this(i want it to be any words i want it to be). i hope you can help me thanks ben import java.io.*; import java.util.*; import java.lang.*; import java.util.StringTokenizer.*;
public class ReadSource { public static void main(String[] args) { try { String Scounter = new String(); int icounter = 1; Hashtable hash = new Hashtable(100); FileReader file = new FileReader("Work.txt"); BufferedReader buff = new BufferedReader(file); String line = buff.readLine(); StringTokenizer s = null; boolean eof = false; while (!eof){ s = new StringTokenizer(line,","); while (s.hasMoreTokens()) { String s2 = s.nextToken(); Scounter = String.valueOf(icounter); hash.put("Scounter",s2); icounter++; for (Enumeration e = hash.elements();e.hasMoreElements();) { String se = (String)e.nextElement(); System.out.println(se ); }
} line = buff.readLine(); if (line == null) eof = true; } buff.close(); }catch (FileNotFoundException fe) { System.out.println("Error - - " + fe.toString()); }catch (NumberFormatException ne) { System.out.println("Error - - " + ne.toString()); } catch (IOException e) { System.out.println("Error - - " + e.toString()); } } }
|
|