473,320 Members | 1,977 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,320 software developers and data experts.

How do i read text file lines into an array

JavaStudent07
I am importing a data file to a sorting method and need to know how to take each line of the imported data and set it equal to an array.

EX.
1.) 2 3 4 5
2.) 3 6 2 6
3.) 9 2 5 6

i want NumberArray[0]==2 3 4 5 and NumberArray[1]==3 6 2 6, etc etc. I think I can work it out if I can get some direction on that.
Mar 23 '07 #1
9 6698
sicarie
4,677 Expert Mod 4TB
I am importing a data file to a sorting method and need to know how to take each line of the imported data and set it equal to an array.

EX.
1.) 2 3 4 5
2.) 3 6 2 6
3.) 9 2 5 6

i want NumberArray[0]==2 3 4 5 and NumberArray[1]==3 6 2 6, etc etc. I think I can work it out if I can get some direction on that.
Do you need help with reading the data in, or assigning it to an array?
Mar 23 '07 #2
assigning to an array
Mar 26 '07 #3
sicarie
4,677 Expert Mod 4TB
assigning to an array
If you read the data in as an int, you can just assign it to the proper place in the array, and if you haven't, you need to do a Java-esque conversion (read: verbose):

Integer.valueOf(yourIntThatIsCurrentlyAString).int Value()
Mar 26 '07 #4
Expand|Select|Wrap|Line Numbers
  1. public class BubbleSort2
  2. {
  3. public static void main (String args[]) throws Exception
  4. {
  5. String filage="";
  6. String Data="";
  7.  
  8. BufferedReader inWords=new BufferedReader(new InputStreamReader(System.in));
  9. System.out.println("Please input the name of the file from which the data will be acquired.  Be sure to use the entire path.");
  10. filage=inWords.readLine();
  11. Data=seekReaderData(filage);
  12. System.out.println(Data);
that is the first part, it is inputted in a String and the print prints out the first line of numbers of the inputted data file, I would like to get the data into an array of strings
<IE>
Array[0]=(Str values) 24 24 24
Array[1]=(Str values) 45 45 45
and so on
Mar 26 '07 #5
67 34 5 6 23 12
56 100 97 97 85
78 67 90
452 78 345 67 888 78


^^^^^^
that is the actual inputted data file that i need to assign each line to an array
Mar 26 '07 #6
sicarie
4,677 Expert Mod 4TB
Do you know there are only going to be 4 lines of data - or is it a set number of lines? Also, are the number of elements on each line set?

I beleive what you want is a 2-d array.
Mar 26 '07 #7
r035198x
13,262 8TB
67 34 5 6 23 12
56 100 97 97 85
78 67 90
452 78 345 67 888 78


^^^^^^
that is the actual inputted data file that i need to assign each line to an array
If you still want to use a 1d array you would have a line at each position in the array with
Expand|Select|Wrap|Line Numbers
  1.  int index = 0; 
  2.  while( (line = inputFile.readLine()) != null) { 
  3.       array[index++] = line;
  4. }
  5.  
...now I think I've written that before ...
Mar 26 '07 #8
any amount of lines, any amount of numbers per line. The teacher is letting us hang out to dry on the actual coding for this project. Sorry if I dont know terminology that you use
Mar 26 '07 #9
sicarie
4,677 Expert Mod 4TB
...now I think I've written that before ...
Ah, you have in this thread.
Mar 26 '07 #10

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

Similar topics

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...
3
by: Konan | last post by:
Pardon the simple question, but I have just begun to learn PHP. So far so good - all the examples in my books actually work. One thing that none of them address is how to read a file of strings...
7
by: Naren | last post by:
Hello All, Can any one help me in this file read problem. #include <stdio.h> int main() {
6
by: G.Esmeijer | last post by:
Friends, I would like to read a text file (fixed length formaated) really fast and store the data into an Access database (2003). Using the streamreader and reading line by line, separating the...
3
by: JenHu | last post by:
Hi, I want read line by line and characters. The characters are fix length text file, no specific delimited method between each fields. The first line is header line, the last line is footer. ...
9
by: Adi | last post by:
Hello eveyone, I wanna ask a very simple question here (as it was quite disturbing me for a long time.) My problem is to read a file line by line. I've tried following implementations but still...
9
by: srikanth | last post by:
i have a text file like below, test.txt file (actually my test file file is with 10000 lines but here i tested with 3 lines) 3 06.09.2006 16:37:25 3 06.09.2006 16:40:02 3 06.09.2006 16:42:31...
7
by: theballz | last post by:
Hi, I am learning c programming and come across a problem i cant seem to solve. I have a file which i wish to parse and put certain lines (which do not contain a hash character) into an array...
5
by: dm3281 | last post by:
Hello, I have a text report from a mainframe that I need to parse. The report has about a 2580 byte header that contains binary information (garbage for the most part); although there are a...
4
by: Keith G Hicks | last post by:
I'm trying to read a text file and alter the contents of specific lines in the file. I know how to use streamreader to read each line of a file. I'm doing that already to get the data into a...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
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: 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: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.