• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

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

 
Ranch Hand
Posts: 634
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 310
1
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how to use split method of string class in this case instead of scanner ?
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 -



 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic