title: How to read from text file and store in String array in Java?
body: <p>I have a text file textfile.txt which contains data as follows :</p>
  
  <pre><code>A-abc , A-xyz , B-mno , A-ijk , B-pqr
  </code></pre>
  
  <p>Now, i have to read from this file and store the values in two separate arrays <code>"A"</code> and <code>"B"</code> , such that the values with prefix <code>"A-"</code> gets stored in array A and values with prefix "B-" gets stored in array B. </p>
  
  <p>Also, while storing the data, the prefix needs to be removed i.e. only <code>"abc"</code> needs to be stored in <code>array A</code>.</p>
  
  <pre><code>FileInputStream fstream = new FileInputStream("C:\opt\New_Workspace\Salary.txt"); 
  // use DataInputStream to read binary NOT text
  // DataInputStream in = new DataInputStream(fstream);
  BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
  String strLine;
  while ((strLine = br.readLine()) != null)   {
  String[] arrayLine1= strLine.split(" , ");
  for(String s:arrayLine1)
  
  String[] arrayLine2 = s.split(": ");
  {
  if(s.matches("Basic: "))
  {
  basic = Double.parseDouble(arrayLine[1]);                 
  }
  else if(s.matches("Perc-D ");
  {
  percD = Double.parseDouble(arrayLine[3]);                
  }
  else if(s.matches("Perc-A: "))
  {
  percA = Double.parseDouble(arrayLine[5]);                 
  }
  
  }
  </code></pre>