473,327 Members | 2,103 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

How to read from file and store some info into array?

i'm really really new to Java. and i came across this question. and i don't know how to do. so if anyone would like to help me in the coding?

Question: i was given a text file in this format.. and was asked to create CD arrays based on the text given. which in this case 4 CD arrays.


[THE TEXT FILE (CD.TXT)]
Expand|Select|Wrap|Line Numbers
  1. 4
  2. River Classic,Michael bubble,23.50,Crazy love,04:26,Hold on,04:01,Hollywood,03:10,At this moment,03:55
  3. Recovery Road,M&Ms,22.00,Love the way you lie,04:23,No love,05:00,Cinderalla Man,04:36
  4. Speak forever,Taylor Swifty,20.00,Mine,03:55,Speak now,04:03
  5. Best of Me,Eric Charles,18.50,River runs deep,03:33,Rocking chair,04:11,Autumn leaves,05:06,How deep is the ocean,04:02,Travelin' Alone,3:29
  6.  
[END OF TEXT FILE]

the first number ('4') is the array of CD need to be created. then I need to spilt the info according to the CD title, singer, price, tracks [into arrays form] & tracks' length [into array form too]
i did split the info [title, singer & price] but i don't know how to read & store the tracks & the tracks' length into the arrays.

can someone help me?
Nov 21 '10 #1
2 2301
Dheeraj Joshi
1,123 Expert 1GB
You can use FileInfupStream classes for this. And do you have a code for this?

Regards
Dheeraj Joshi
Nov 22 '10 #2
i tried to do it like this.

Expand|Select|Wrap|Line Numbers
  1. public static void main(String[] argv) {
  2.  
  3.     BufferedReader br = new BufferedReader(new FileReader ("CD.txt"));
  4.  
  5.     int count = Integer.parseInt(br.readLine());
  6.  
  7.     String title = "";
  8.     String singer = "";
  9.     Double price = 0.0;
  10.     String category = "";
  11.     String discount = "";
  12.     String tracks [] = new String [30];  // i just make 
  13.     String length [] = new String [30];  // an array of 30s
  14.  
  15.      for (int i=0; i<count; i++) {
  16.             String s = br.readLine();
  17.             StringTokenizer st = new StringTokenizer(s, ",");
  18.  
  19.             title = st.nextToken();
  20.             singer = st.nextToken();
  21.             price = Double.parseDouble(st.nextToken());
  22.             category = st.nextToken();
  23.             discount = st.nextToken();
  24.  
  25.              System.out.println("Title: " + title + "\nSinger: " + singer + "\nprice: " + price +
  26.             "\ndiscount :" + discount + "\ncategory:" + category);
  27.  
after that, i dont know how to read the tracks & the lengths from the file & store them into the tracks[] and trackLength[] respectively.
Nov 22 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Kevin Knorpp | last post by:
Hello. I need to be able to extract the data from the attached file (or any file in the same format) so that I can work with the data in PHP. I'm fairly comfortable with using PHP with...
5
by: deko | last post by:
I have a text file ("eighty.txt") that looks like this: 83|84|85|86 I can read the file into an array like this: $numbers= file("eighty.txt"); But how do I key the array? I'd like to use...
11
by: Colin Steadman | last post by:
Hope this makes sense! I'm building an ASP page which allows uses to add items to an invoice via a form, ie: Item No Part No Order No Quanity Units Price VAT ------- ...
7
by: ianenis.tiryaki | last post by:
well i got this assignment which i dont even have a clue what i am supposed to do. it is about reading me data from the file and load them into a parallel array here is the question: Step (1) ...
3
by: lalala | last post by:
i need to retrieve the data stored in binary format from file into an array to make comparison.Can some1 write me a sample program ?? ermm something like below... ifstream...
1
by: alkandry911 | last post by:
hello, Everyone, am new to C Code and I have a little task am trying to achieve: I have a text file with a table of 15*30 which has the following format: ksjdhfbrshyuekjdhsngfurjsleotj...
3
by: almo | last post by:
hi guys, I have question about writing a function that will store some data from a file in an array, then when that function is call in main, I can use that array in the main() for calculation. Here...
3
by: ryokubaka | last post by:
In the following code, I have a function that is called in main by the line Array = Load_File (Filename, &Size); The function is suppose to do, as the title would suggest, load a file of...
3
by: Arjun Sarankulu | last post by:
I want to read numbers from XML file Suppose xml file contain <number>1</number> <number>10</number> <number>20</number> <number>30</number> <number>69</number> The above mention numbers in...
1
by: Jollywg | last post by:
I have a script that gets all the computer names on the network and saves them as compnames.txt. I would like to read or insert all of the names (delineated by new line) into an array or power shell...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.