I have a text file textfile.txt which contains data as follows :
A-abc , A-xyz , B-mno , A-ijk , B-pqr
Now, i have to read from this file and store the values in two separate arrays "A"
and "B"
, such that the values with prefix "A-"
gets stored in array A and values with prefix "B-" gets stored in array B.
Also, while storing the data, the prefix needs to be removed i.e. only "abc"
needs to be stored in array A
.
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]);
}
}