The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
January 2002

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

try using StringTokenizer......

Posted by Manpreet on January 11, 2002 at 7:39 AM

Hi Angelika,

hope the following code is of some use to you....

//-----------------------------------------
import java.io.*;
import java.util.StringTokenizer;
import java.util.*;

class ReadNumbers
{
public static void main (String args[])
{
try
{
FileReader fr = new FileReader("c:/file.txt");
BufferedReader br = new BufferedReader(fr);
String str ="";
Vector vec = new Vector();
do
{
str = br.readLine();
if(str==null)
break;
StringTokenizer st = new StringTokenizer(str);
while (st.hasMoreTokens())
{
String value = st.nextToken();
vec.add(value);
}
}while(str!=null);

int arr[] = new int[vec.size()];
for(int i=0;i {
arr[i] = Integer.parseInt((String)vec.elementAt(i));
System.out.println(arr[i]);
}
}
catch(Exception e)
{
System.out.println("Exception:" + e.getMessage());
}
}
}


do lemme know if it's of some help
warms regards
Minhas





Replies:
  • Thanx Angelika January 24, 2002 at 1:48 PM (0)

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us