Ok I'm trying to read a file line by line and then check for instances of the line for display. Well it will read the file in but instead of reading from the line that I want it just reads from the first line...here is a sample of what I have:
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
public class testImporter{
String LineID;
public static void main (String args[]) throws Exception {
File file = new File("C:\\Data");
if (!file.exists()) {
System.out.println("Can't read " + file);
}
else {
if (file.isDirectory( )) {
String [] files = file.list( );
for (int i=0; i< files.length; i++) {
String ifile = files[i];
doit (file + File.separator + ifile);
}
}
else {
doit(args[0]);
}
}
}
public static void doit (String ifile) throws Exception {
String lineID1 = "GS";
method12(ifile,lineID1);
}
public static void method12(String ifile, String lineID1) throws Exception {
BufferedReader inData = new BufferedReader(new InputStreamReader(new FileInputStream(ifile)));
String newLine ="\012";
String line = "";
String str1 = "";
String str2 = "";
String fLine = "";
boolean firstTime = true;
while ((line = inData.readLine()) != null) {
fLine = fLine + (firstTime?"":newLine) + line;
if (firstTime) firstTime = false;
}
inData.close();
if (fLine.indexOf(lineID1) >= 0) {
StringTokenizer st = new StringTokenizer(fLine, "|");
String GS = st.nextToken();
String locat2 = st.nextToken();
String Shipto = st.nextToken();
String Shipfrom = st.nextToken();
String locat5 = st.nextToken();
String locat6 = st.nextToken();
String locat7 = st.nextToken();
String locat8 = st.nextToken();
String locat9 = st.nextToken();
System.out.println("there is:" + Shipto);
System.out.println("there is:" + Shipfrom);
}
}
}
This compiles and runs but instead of reading from the second line (where lineID1 is) it just takes the data from the first line. Any Ideas on how to fix this?