0

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();
                index++;
           }
4
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by BestJewSinceJC
0

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:

http://lmgtfy.com/?q=java+Reading+and+writing+text+files

0

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.