File f = new File("<path to file>");
BufferedReader d = new BufferedReader(new FileReader(f));
while ((s=d.readLine()) != null) {
System.out.println(s);
}
if you want to parse out the words delimited by the space.
StringTokenizer st;
while ((s=d.readLine()) != null) {
st = new StringTokenizer(s, " ");
while (st.hasMoreTokens()) {
System.out.println(st.next
}
}
d.close();
Main Topics
Browse All Topics





by: TimYatesPosted on 2003-01-29 at 13:31:04ID: 7841109
private Vector readInData( String filename ) throws IOException
{
Vector ret = new Vector() ;
File file;
BufferedReader fileReader;
file = new File( filename );
fileReader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
if(file.exists())
{
String line = fileReader.readLine();
while( line != null )
{
ret.addElement( line ) ;
contact = fileReader.readLine(); //Get next contact from file
}
}
fileReader.close();
return ret ;
}
will return you a Vector with ret.size() lines from the file
Then:
Vector v = readInData( "theFile.dat" ) ;
for( int i = 0 ; i < v.size() ; i++ )
{
String line = (String)v.elementAt( i ) ;
StringTokenizer st = new StringTokenizer( line ) ;
while (st.hasMoreTokens())
{
println(st.nextToken());
}
}
should do it