JavaDemo2 Version2 Using Separately Compiled Classes
import java.io.*;
import java.util.Vector;
public class JavaDemo2Vers2
{
public static void main(String[] args){
String infileName = new String("sampleFile.txt");
String outfileName = new String("sampleFileOut.txt");
String sample = new String("String+nulls\0\0\0\0\0");
char sample2[] = new char[80];
int numValue;
boolean arrayNumbers=false;
Vector intArray;
sample2 = ("Another string with nulls:\0\0\0\0\0\0\0\0\0").toCharArray();
System.out.println("String with null: " + sample + " characters");
System.out.println("Another sample with nulls: " +
String.copyValueOf(sample2));
try{
BufferedReader infile =
new BufferedReader(new FileReader(infileName));
// Open for reading
System.out.println("File open for reading...");
BufferedWriter outfile =
new BufferedWriter(new FileWriter(outfileName));
// Open for writing
System.out.println("File open for writing...");
String line;
while((line = infile.readLine()) != null)
{
System.out.println(line); // routes output to CRT
if (line.startsWith("this is a line with strings and a number"))
{
numValue = StringProcessor.getNumValue(line);
System.out.println("This line has the number: " + numValue);
}
if (arrayNumbers)
{
intArray = new Vector();
intArray = VectorProcessor.getIntArray(line);
System.out.print("Here's the array: ");
VectorProcessor.printArray(intArray);
}
if (line.startsWith("5 more numbers:"))
arrayNumbers = true;
else arrayNumbers = false;
outfile.write(line, 0, line.length()); // routes output to file
outfile.newLine();
}
System.out.println("Done copying file...");
infile.close();
outfile.close();
System.out.println("Files closed.");
}
catch(IOException e){
System.err.println(e);
return;
}
}
}