The Artima Developer Community
Sponsored Link

Java Answers Forum
text files

17 replies on 2 pages. Most recent reply: Nov 7, 2002 3:13 AM by ben

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 17 replies on 2 pages [ « | 1 2 ]
ben

Posts: 57
Nickname: loftty
Registered: Oct, 2002

Re: text files Posted: Nov 5, 2002 2:26 AM
Reply to this message Reply
Advertisement
hello Ramu
i hope you can help me with this hash table? i know it is a key value object.
what i want to do is read though each word in the incoming text file and then each word would be put into a hash table . how do i go about doing this or is there a better way to store the text ie in a array or somthing else?
at the end all i want to do is to type in system out print (key value or array 1) and by doing this it will print out the first word could u please give any suggestions or if u feel realy nice write me out some sample code.
thanks for yr time ben

Ramu

Posts: 29
Nickname: sripoorna
Registered: Oct, 2002

Re: text files Posted: Nov 5, 2002 4:32 AM
Reply to this message Reply
hi ben,

for reading the first word and putting it in to the hashtable we can go for an arrylist or vector.
As u r saying that u just want to print out then there is no need to go for hashtable better to go for arraylist or vector.

u use this code

ArrayList arrList = new ArrayList();
arrList.add("first word");

for printing the arraylist use the Iterator


regards
ramu

ben

Posts: 57
Nickname: loftty
Registered: Oct, 2002

Re: text files Posted: Nov 7, 2002 3:13 AM
Reply to this message Reply
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());

}
}
}

Flat View: This topic has 17 replies on 2 pages [ « | 1  2 ]
Topic: Java help please Previous Topic   Next Topic Topic: Help please

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use