Using a static method to read data from text file

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jan 2009
Posts: 21
Reputation: jdbarry is an unknown quantity at this point 
Solved Threads: 0
jdbarry's Avatar
jdbarry jdbarry is offline Offline
Newbie Poster

Using a static method to read data from text file

 
0
  #1
Feb 20th, 2009
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...

  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. }
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 277
Reputation: rapture has a spectacular aura about rapture has a spectacular aura about 
Solved Threads: 37
rapture rapture is offline Offline
Posting Whiz in Training

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

 
0
  #2
Feb 20th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 16
Reputation: danielernesto is an unknown quantity at this point 
Solved Threads: 1
danielernesto danielernesto is offline Offline
Newbie Poster

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

 
0
  #3
Feb 20th, 2009
Im a little curious, you want to create that method in the same class or in other class an them invoke it??.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,658
Reputation: BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold 
Solved Threads: 206
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

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

 
0
  #4
Feb 20th, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1178 | Replies: 3
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC