-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

1

3 Answers 3

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

`

Sign up to request clarification or add additional context in comments.

Comments

2

You can split the file line by new line.

String [] names = fileString.split("\n");

Comments

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"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.