reading from file

Reply

Join Date: Oct 2008
Posts: 4
Reputation: sahrourr is an unknown quantity at this point 
Solved Threads: 0
sahrourr sahrourr is offline Offline
Newbie Poster

reading from file

 
0
  #1
Nov 22nd, 2008
hello i need a help, if i have a text file that contains something like this:
account num name credit account type
1 sara 1000 current
2 jerry 5000 comercial

i wanna get out the number in the credit coloumn to add or subtract from it and i don't know how to do it i think we will use 2D array but i don't know how, i tried to use index of method but it only can get the line which contains the name i entered but i can't get the credit it self, plz help me
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,563
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 196
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

Re: reading from file

 
0
  #2
Nov 22nd, 2008
What you posted above doesn't really make sense. Make sure to clearly explain what you mean. On one hand, your thread title makes it seem like you are having trouble reading stuff in from the file. If that is the case, then why are you talking about indexOf()? indexOf() is not used to read from the file.

An example of how to read from a file which contains:

an integer on the first line
a sentence (String) on the second line

  1. Scanner readFile = new Scanner(new FileInputStream("filename.txt"));
  2. int firstInt= readFile.nextInt();
  3. String secondLine = readFile.nextLine();

Obviously, I didn't just solve your problem for you, I gave you an example of how to do it. With that, you should be able to figure it out. If you aren't sure what methods to use (for example, how would you read in a decimal value such as 3.556?) then google "Java Scanner" and read the documentation for the Scanner class.
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC