Filtering Ascii file using Java Help

R

reblfan

I am by no means a programmer, but I was given the task of reducing
the size of a very large Ascii document using certain criteria. I
chose to write this in Java, since this is the language that is most
fresh on my mind. The data for the input file was obtained using some
instruments and it has a certain format. The format is 3 header lines
at the top and then a series of six description lines followed by six
data lines. There are 14 columns total in each data row. I was to
filter out data in two of these columns according to certain
specification and only write the six description lines if at least one
of the six data lines below it were written. The basic idea of my code
seems to work, because it properly extracts the data I need from the
ascii file and writes it to another text file. The problem is that
stops writing data in the middle of a line. It stops at the same place
everytime and after viewing the location in the ascii file where it
happens, I can see no differences. The file I am working on is a
little over 3 MB, but I need to do this with a combined 75 MB file.
Here is my code, as inefficient as it is. If anyone wants to see the
ascii document then I can send it via e-mail. Thanks.

import java.io.*;
import java.util.*;
import java.lang.*;

public class shields{
public static void main(String args[])
{
FileReader f = null;
BufferedReader inFile = null;
FileWriter fout = null;
try{
fout = new FileWriter("final.txt");
}
catch(Exception e){}
StringTokenizer tokenizer;
String currentToken;
String percentToken = null;
int i, j;
int x=0;
double current;
double percent;
try{
f = new FileReader("c:\\PVC20040616123534_000t.txt");
inFile = new BufferedReader(f);
}

catch(Exception e){}

String[] arr = new String[6];
String lineOut=null;

for(i=0; i<6; i++){
arr = null;
}

for(i=1; i<=3; i++){
try{
lineOut = inFile.readLine();
fout.write(lineOut + "\n");
}
catch(Exception e){}
}
try{
while((arr[0] = inFile.readLine()) != null){
x=0;
for(i=1; i<=5; i++){
try{
arr = inFile.readLine();
}
catch(Exception e){}
}

for(j=1; j<=6; j++){
try{
lineOut = inFile.readLine();
}
catch(Exception e){}
tokenizer = new StringTokenizer(lineOut);
currentToken = tokenizer.nextToken();
current = (new Double(currentToken)).doubleValue();
for(i=1; i<=11; i++){
percentToken = tokenizer.nextToken();
}
percent = (new Double(percentToken)).doubleValue();
if(current > .69 || percent < 100){}
else{
if(x == 0){
for(i=0; i<6; i++){
try{
fout.write(arr + "\n");
}
catch(Exception e){}
}
}
x=1;
try{
fout.write(lineOut + "\n");
}
catch(Exception e){}
}
}
}
}
catch(Exception e){}
}
}
 
M

Michael Borgwardt

reblfan said:
of the six data lines below it were written. The basic idea of my code
seems to work, because it properly extracts the data I need from the
ascii file and writes it to another text file. The problem is that
stops writing data in the middle of a line.

Try calling close() on the output writer at the end of your program.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top