Java: How to store string values from a text file?
-
so i have this text file that is formatted like this ObjectA, name1, name2 ObjectB, name3, name4 ObjectC, name5, name6 i am having trouble trying to save the names and the objects. how would i save these string values with commas that separate them??
-
Answer:
You can use the next() method of the Scanner class. It will get each word delimited by a white-space. Scanner scan = new Scanner("your file") ; String s ; while (scan.hasNext() ) { s = scan.next() ; /* Then you want to remove the comma */ s[s.length] = '\0' ; /* and then insert it into whatever data structure you want */
Cliff at Yahoo! Answers Visit the source
Related Q & A:
- How to store different values with the same key in memcache?Best solution by stackoverflow.com
- How can store sqlplus query in a file in formatted manner and display it to console?Best solution by Stack Overflow
- How to extract frequency range from a Wav file?Best solution by Stack Overflow
- Is there a limit on the size of a new file or a text file?Best solution by Stack Overflow
- How can i send some one a text through my computer?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.