943,515 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 2442
  • Java RSS
Feb 20th, 2009
0

Using a static method to read data from text file

Expand Post »
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...

Java Syntax (Toggle Plain Text)
  1. int index = 0;
  2. double[] surfaceGravity = new double[10];
  3. File gravity = new File("surfaceGravityData.txt");
  4. Scanner inFile = new Scanner(gravity);
  5.  
  6. while (inFile.hasNextDouble())
  7. {
  8. surfaceGravity[index] = inFile.nextDouble();
  9. index++;
  10. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jdbarry is offline Offline
21 posts
since Jan 2009
Feb 20th, 2009
0

Re: Using a static method to read data from text file

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+an...ing+text+files
Reputation Points: 155
Solved Threads: 41
Posting Whiz in Training
rapture is offline Offline
294 posts
since Jul 2007
Feb 20th, 2009
0

Re: Using a static method to read data from text file

Im a little curious, you want to create that method in the same class or in other class an them invoke it??.
Reputation Points: 9
Solved Threads: 2
Newbie Poster
danielernesto is offline Offline
16 posts
since Nov 2007
Feb 20th, 2009
0

Re: Using a static method to read data from text file

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.
Reputation Points: 874
Solved Threads: 352
Posting Maven
BestJewSinceJC is offline Offline
2,758 posts
since Sep 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Toolkit class has no getDefaultToolkit method?
Next Thread in Java Forum Timeline: Java+LDAP





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC