• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



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
 
Rajeev Rnair
Ranch Hand
Posts: 310
1
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to use split method of string class in this case instead of scanner ?
 
Pradeep Kr
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 -



 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic