Hello all,
I created a program which I can type in a line and store it into a file. What I need my next program to do is read and display just the first word from each line on the text file.
Here is what I have:
import java.io.*;
public class ReadFromFile
{
public static void main (String args[])
{
FileInputStream firstWord;
try
{
// Open an input stream
firstWord = new FileInputStream ("FileofWords.txt");
// Read a line of text
System.out.println( new DataInputStream(firstWord).readLine() );
// Close our input stream
firstWord.close();
}
{
System.err.println ("Unable to read from file");
System.exit(-1);
}
}
}