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++;
           }

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

Im a little curious, you want to create that method in the same class or in other class an them invoke it??.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.