🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: aus.computers.java
1 messages
1 total messages Started by M.T. Mon, 22 Aug 2005 22:35
Writing Java driver to read from textfile
#135
Author: M.T.
Date: Mon, 22 Aug 2005 22:35
72 lines
2518 bytes
I have a class to read text input from a text file one line at a time.

I am having great difficulty writing a driver to text this class.

Thanks

Margaret


 // Class TextIO
// required imports
import java.io.*;

class TextIO
{

 public static void fileRead() throws IOException{
  int total = 0;
  int value;
  String line;
  BufferedReader inFile=null;
  String fileName="data.txt";
  try{
       inFile=new BufferedReader(new FileReader (fileName));
       while (true){
           try{
                line=inFile.readLine();
                if (line==null)
                     break;
                value=Integer.parseInt(line);
                total+=value;
           }

      catch(NumberFormatException exception){
       System.out.println("That's not a number");
      }
  }
  System.out.println("Total is: " + total);
  inFile.close();

} catch (FileNotFoundException e){
 throw e;
}
}//end fileRead method
}



TextTest.java

// Class TextTest
// calls to test the methods in TextIO

// required imports
import java.io.*;

class TextTest
{

 public static void main(String[] argv){

 // declare variables
     String fileRead;

     System.out.println("Start Testing TextClass");

//*************  - what am I getting from TextIO ????????
      fileRead = TextIO.fileRead();
      System.out.println("The string returned is: "+ fileRead);
      System.out.println("Finish Testing TextClass");
 }
} 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads