File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Reading data from a file and storing into array of strings problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Reading data from a file and storing into array of strings problem" Watch "Reading data from a file and storing into array of strings problem" New topic
Author

Reading data from a file and storing into array of strings problem

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634




movies.txt


what code should i put here so that abc[0],abc[1],abc[2] stores the first line of movies.txt
and abc[3] to abc[5] stores the second line of movies.txt asnd so on....


i tried the follwing code in the while loop but it doesnot work


error
DVDInfo.java:54: incompatible types
found : java.lang.String[]
required: java.lang.String
{ab=s.split("/");}
^
1 error


tell me the code to store data from file into array of strings


OCPJP 6.0 93%
OCPJWCD 5.0 98%
Rajeev Rnair
Ranch Hand

Joined: Mar 22, 2010
Posts: 308

Hi Mohit, I used a Scanner for parsing. Please see my code ( I was lazy to put any comments there Sorry about that ) The parsing logic is in readDVDFile() method.


SCJP6, SCWCD5, OCP-JBCD5, OCE-JWSD6 OCE-JPAD6 , OCM-JEA5 1,OCM-JEA5 2,3 - Brainbench certifications: J2EE, Java2, Java2-NonGUI, JSP, SQL2000 Admin, SQL2000 Programming , Brainbench certified Java Programmer, Computer Programmer, Web Developer, Database Administrator
Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

how to use split method of string class in this case instead of scanner ?
Pradeep Kr
Greenhorn

Joined: Feb 17, 2010
Posts: 22
Problem with array is you can not have dynamically increasing array. You need to specify size, when you initiate array.
In your example, I am assuming you don;t know how many DVDInfo are there in your movies.txt file. With minimum changes to your code, Here is what i think should work.

This is the block of code I changed


Here is the complete code -



 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading data from a file and storing into array of strings problem