
This is the J2ME code for the ResetNulls class. This class is used to reset the values in the index.txt file back to NULL at the end of a search in Pepperpot.
This approach helps to keep the size of the program down by having one reusable temporary storage point for search criteria rather than a new instance of a text file for each search.
The ResetNulls class uses the J2ME FileReader, FileWriter, PrintWriter and StreamTokenzier constructors for I/O to the text file.
//Created by Paul Timney, April 2005
//Class to reset the values of index.txt back to NULL so it can be reused on each new search for a recipe
import java.awt.*;
import java.io.*;
public class ResetNulls
{
//global variables
public String name;
public double question;
public ResetNulls() throws IOException
{
//new file reader which take nulls.txt as the parameter
FileReader inputFile = new FileReader("\\My Documents\\recipes\\nulls.txt");
//new file writer that takes index.txt as the parameter
FileWriter output = new FileWriter("\\My Documents\\recipes\\index.txt");
PrintWriter outputFile = new PrintWriter(output);
//stream tokenizer for input file
StreamTokenizer input = new StreamTokenizer(inputFile);
input.wordChars(0x20,0x7F);
int tokenType;
//set tokentype to the first value in nulls.txt
tokenType = input.nextToken();
//while loop that operates while the tokenType value
does not equal the end of the input file. This loop takes the question number
and String value from nulls.txt and writes them out in the same position to
index.txt, effectively blanking the output file.
while (tokenType !=StreamTokenizer.TT_EOF)
{
question = input.nval;
tokenType = input.nextToken();
name= input.sval;
outputFile.println(question+"\t"+name);
tokenType = input.nextToken();
}
//close file reader and file writer
inputFile.close();
output.close();
}
}
//END OF CLASS