I am need a little guidance here as to how I am to go about using a static method to read data from a text file. I know how to use a static method to write data to a text file, now I am wondering how to use a static method to read data from a text file. The following code is the code that read the data from the text file in the main method. Now that the code works in the main method, I am wondering how I can create a static method that does this. Thanks in advance to the person that has some ideas for me on this...

int index = 0;
        double[] surfaceGravity = new double[10];
        File gravity = new File("surfaceGravityData.txt");
        Scanner inFile = new Scanner(gravity);
        while (inFile.hasNextDouble())
                surfaceGravity[index] = inFile.nextDouble();
9 Years
Discussion Span
Last Post by BestJewSinceJC

I'm not totally sure where you're stuck. Have you tried to google this? I did and the first result has an example of a static read . . .

are you unsure of the concepts? are you trying but getting an error? I'm sorry, I'm just not sure what it is you are asking

you can look here - first result returned might be helpful:



The code is the same in a static method as it would be in main. and main is a static method - just look at the method header.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.