mrchimp
Newbie
- Joined
- Jul 19, 2003
- Messages
- 1,928
- Reaction score
- 0
I just made my first Java app and I must say my experience with Java so far has been very good. Only haveing to reffere to one API is fantastic and the way java forces you to do certain things is brilliant. The documentation isn't half bad either, although it seams to presume you already know a programming language when it comes to a certain subjects.
As for speed which is why i have never used it untill now, I can't say it's that slow atall. I'm sure it's quite a bit slower than native code but java programs like Azureus never slow down or slow my comp down (even when gameing).
Anyway here's my program, I call it a parser but it's probably just a filter, I used the netbeans IDE which is pretty damn good too:
As for speed which is why i have never used it untill now, I can't say it's that slow atall. I'm sure it's quite a bit slower than native code but java programs like Azureus never slow down or slow my comp down (even when gameing).
Anyway here's my program, I call it a parser but it's probably just a filter, I used the netbeans IDE which is pretty damn good too:
Code:
/*
* FilerParser.java
*
* Created on 20 May 2004, 22:03
*/
package FileReader;
import java.io.*;
/**
*
* @author Chimp
*/
public class FileParser {
FileReader OpenIF(String PathN){ //Open Input File
FileReader TextF = null;
boolean rdy = false;
try{
TextF = new FileReader(PathN);
}
catch(FileNotFoundException e){
System.out.println("Input File Not found");
System.exit(0);
}
try{
rdy = TextF.ready();
}catch(IOException e){
System.out.println("Input File Can not be read: IOException");
System.exit(0);
}
if(rdy == true){
System.out.println("Input File is ready to be read");
}else{
System.out.println("Input File can not be read");
System.exit(0);
}
return TextF;
}
FileWriter OpenOF(String PathN){ //Open Output file
FileWriter TextF = null;
try{
TextF = new FileWriter(PathN);
}catch(IOException e){
System.out.println("Output File can not be opened");
System.exit(0);
}
return TextF;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
FileReader TextIF = null;
FileWriter TextOF = null;
FileParser FP = new FileParser();
int FileS = 5000000; //Guestimate File size in chars with room to spare
int Counter = 0;
boolean EOT = false; //End of text
TextIF = FP.OpenIF("c:\\E-mails.txt");
TextOF = FP.OpenOF("c:\\mail.txt");
char TextI[] = new char[FileS]; //array of characters, about 9.5mb in size
char TextO[] = new char[FileS];
try{
TextIF.read(TextI);
}catch(IOException e){
System.out.println("Read Error");
System.exit(0);
}
for(int I = 0, N = 0; I <= FileS; I++, N++){
switch(TextI[I]){
case ' ':{ //When a space is found it skips 6 chars to filter out the crap
I += 6;
TextO[N] = ';'; //puts a ";" in the space
Counter++;
break;
}
case '|':{ // "|" indicates the files end
EOT = true;
break;
}
default:{
TextO[N] = TextI[I]; //Copy's the valid char
break;
}
}
if(EOT) break;
}
try{
TextOF.write(TextO);
}catch(IOException e){
System.out.println("Write Error");
System.exit(0);
}
System.out.println("Text Parsed");
System.out.println("File contains: "+Counter+" Emails");
System.exit(0);
}
}