| | |
reading from file
![]() |
•
•
Join Date: Oct 2008
Posts: 4
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Sep 2008
Posts: 1,563
Reputation:
Solved Threads: 196
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
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.
An example of how to read from a file which contains:
an integer on the first line
a sentence (String) on the second line
Java Syntax (Toggle Plain Text)
Scanner readFile = new Scanner(new FileInputStream("filename.txt")); int firstInt= readFile.nextInt(); 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.
![]() |
Similar Threads
- Reading from file, passing into function. (C)
- Help on a reading from a file programming (Java)
- Need help reading a file (C++)
- Reading a file into a Parallel Array (C++)
- problems with reading in file (C++)
- First year assigment on reading file, sorting and outputting invoice (C++)
- Error Message Concerning Reading File From A Drive (C++)
- reading a file into code (Java)
Other Threads in the Java Forum
- Previous Thread: Hash Table
- Next Thread: Exception in thread "main" java.lang.StackOverflowError
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary block bluetooth character class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game gameprogramming givemetehcodez graphics gui html ide image integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loops mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing system test textfields threads time title tree tutorial-sample ubuntu update windows working






