-1

I have a file that looks similar to this

 12345 one
 12345 two
 12345 three
 ....... 

Question is how can i get all of the values from second row and store them in a String[] i know how to read file in java just dont know how to cut the second row

Kappa
  • 1,015
  • 1
  • 16
  • 31
pedja
  • 3,285
  • 5
  • 36
  • 48
  • you could do something like this http://stackoverflow.com/a/285745/584026 and then get the 2nd element (`array[1]`) – Grace B Aug 11 '12 at 09:35

3 Answers3

4

1. Store Each line from the file into an ArrayList<String>, its more flexible than String[] array.

2. Then access the line you need by get() method of ArrayList

Eg:

ArraList<String> arr = new ArrayList<String>();

//Now add each lines into this arr ArrayList

arr.get(1);         // Getting the Second Line from the file

`

Kumar Vivek Mitra
  • 33,294
  • 6
  • 48
  • 75
2

You can split the file line by new line.

String [] names = fileString.split("\n");
Mohammod Hossain
  • 4,134
  • 2
  • 26
  • 37
0

Ok this is what i did but it skips first line

  FileInputStream fstream = new FileInputStream("/sys..........");

          DataInputStream in = new DataInputStream(fstream);
          BufferedReader br = new BufferedReader(new InputStreamReader(in));
          String strLine;

          strLine = br.readLine();
          while ((strLine = br.readLine()) != null)   {

              delims = strLine.split(" ");
               first = delims[1];
               where.add(first);

          }

          in.close();

From example above it contains only "two" and "three"

pedja
  • 3,285
  • 5
  • 36
  • 48