backa gain for more advice
I need to make this:
//Open the input stream from the file
FileInputStream instr =new FileInputStream(file);
//Enable the buffered reader
BufferedReader in =new BufferedReader(new InputStreamReader(instr));
//Holds a line of the file
String fileLine =new String();
//Continue parsing until the end of the file is reached
while((fileLine = in.readLine()) !=null)
{
//This condition applies to the first section of the file
//which does not contain any mole fraction data. The parser
//pulls the x data from this section.
if(fileLine.toLowerCase().indexOf("x(cm)") > -1
&& fileLine.toLowerCase().indexOf("mole fractions") == -1)
{
//Take in a line of data
fileLine = in.readLine();
//The line immediately following all the data has no content
while(fileLine.length() > 0)
{
//X data always starts at position 7 in the file
xValue =new Double(fileLine.substring(7, fileLine.indexOf(" ",7)));
//Convert to mm
xValue =new Double(xValue.doubleValue()*10);
//Set the value in the x column
x.setValue(xValue.toString());
//Take in the next line of data
fileLine = in.readLine();
}
}
//This condition applies to the following sections of the file
//that contain mole fraction data. The parser pulls all y data
//from these sections
if(fileLine.toLowerCase().indexOf("x(cm)") > -1
&& fileLine.toLowerCase().indexOf("mole fractions") > -1)
{
//Count of the columns of molecule data in this section
int columns = 0;
//Take in the line that contains molecule id header info
fileLine = in.readLine();
//Go through the header, creating a new molecule for each
//new molecule id in the header
for(int i = 0; i < fileLine.length(); i++)
{
//Molecule id's are separated by several spaces
if(fileLine.charAt(i) !=' ')
{
//Obtain the id as a substring
formula = fileLine.substring(i, fileLine.indexOf(" ", i));
System.out.print("Enter a name for molecule " + formula
+" :> ");
name = user.readLine();
//Create a new molecule and increase the counters
Column yNew =new Column();
yNew.copyHeader(y);
molecules[counter] =new Molecule(name, formula, x, yNew);
counter++;
columns++;
//Skip the for-loop counter to the next occurence of
//a space
i = fileLine.indexOf(" ", i);
}
}
//Take in the next line of data
fileLine = in.readLine();
//The first molecule index number of a section. We need to
//subtract and extra 1 since Column 1 corresponds with
//Molecule 0 due to the existence of an X column at the
//beginning of each section
int start = counter - columns - 1;
//Temporary holder for data entries
String value =new String();
//Go through a section of y data, parsing data from the columns
//and putting it into the appropriate molecule's y data
while(fileLine.length() > 0)
{
//Counter for the columns in this section
int colSection = 0;
//i represents the character position in the row.
//Starts at 5, which is the start position for the first
//column of data.
for(int i = 5; i<fileLine.length(); i++)
{
if(fileLine.charAt(i) !=' ')
{
if(colSection == 0)
{
i = fileLine.indexOf(" ", i);
colSection++;
}
elseif(colSection > 0 && colSection < columns)
{
value = fileLine.substring(
i, fileLine.indexOf(" ", i));
molecules[start + colSection].y.setValue(value);
i = fileLine.indexOf(" ", i);
colSection++;
}
else
{
value = fileLine.substring(i);
molecules[start + colSection].y.setValue(value);
i = fileLine.length();
colSection++;
}
}
}
fileLine = in.readLine();
}
take in things that are tab delimited like this one can:
while((fileLine = in.readLine()) !=null)
{
int tabIndex = fileLine.indexOf('\t');
x.setValue(fileLine.substring(0,tabIndex));
y.setValue(fileLine.substring(tabIndex+1));
}
Any advice?

