ben
Posts: 57
Nickname: loftty
Registered: Oct, 2002
|
|
Re: for loop to read in every 10th word
|
Posted: Nov 13, 2002 5:55 AM
|
|
thanks daniel but how would i put the hashtable into a array list can you give me some examples please or adjust my code please thanks ben
import java.io.*; import java.util.*; import java.lang.*; import java.util.StringTokenizer.*;
public class RT { public static void main(String[] args) { String cT = null; String lT = null; try { //int ic = 1; 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.trim(),",",true); while (s.hasMoreTokens()) { cT = s.nextToken(); Scounter = String.valueOf(icounter); if (cT.equals(",") && (lT != null) && lT.equals(",")){ hash.put(Scounter,""); } else { if (!cT.equals(",")) { hash.put(Scounter,cT); } } lT = cT; icounter++; } line = buff.readLine(); if (line == null) eof = true; } for (Enumeration e = hash.elements();e.hasMoreElements();) { String se = (String)e.nextElement(); System.out.println(se); } 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()); } } }
|
|