Hi,
I am new to java. I am trying to read and clean several text files from a directory than the working one .
I am using relative path to do that. I have a mac and I am using command window. I have absolutely no
idea why the program is not working. Below is the program and output. I would appreciate
any input. Thanks.
/*
* mclean3.java
*/
import java.io.*;
import java.util.*;
public class mclean3 {
public static void main(String args[]) {
if(args.length == 0) {
System.err.println("usage: java Type directory name ");
} else {
String path = args[0];
File folder = new File(path);
File[] listOfFiles = folder.listFiles();
String files;
String wfile;
BufferedReader br = null;
String line = null;
String pattern = "[^A-Za-z]";
for(int i = 0; i < listOfFiles.length; i++) {
files=listOfFiles[i].getName();
System.out.println( System.getProperty( "user.dir" ) );
System.out.println(path);
wfile = "\""+path+"/"+files+"\"";
try {
System.out.println(files);
System.out.println(wfile);
br = new BufferedReader(new FileReader(wfile));
line = br.readLine();
while(line != null) {
//line = line.replaceAll(pattern, " ");
System.out.println(line);
//line = br.readLine();
}
br.close();
} catch(FileNotFoundException exc1) {
System.err.println(" File "+wfile+" not found");
} catch(IOException exc2) {
System.err.println("Input/Output error with the file "+wfile);
}
}
}
}
} // end of class mclean3
hamy-temkits-macbook-pro:javatutorial mtemkit$ emacs
hamy-temkits-macbook-pro:javatutorial mtemkit$ javac mclean3.java
hamy-temkits-macbook-pro:javatutorial mtemkit$ java mclean3 ~/Desktop/java/javatutorial/hfiles
/Users/mtemkit/Desktop/java/javatutorial
/Users/mtemkit/Desktop/java/javatutorial/hfiles
.DS_Store
"/Users/mtemkit/Desktop/java/javatutorial/hfiles/.DS_Store"
File "/Users/mtemkit/Desktop/java/javatutorial/hfiles/.DS_Store" not found
/Users/mtemkit/Desktop/java/javatutorial
/Users/mtemkit/Desktop/java/javatutorial/hfiles
1911.txt
"/Users/mtemkit/Desktop/java/javatutorial/hfiles/1911.txt"
File "/Users/mtemkit/Desktop/java/javatutorial/hfiles/1911.txt" not found
/Users/mtemkit/Desktop/java/javatutorial
/Users/mtemkit/Desktop/java/javatutorial/hfiles
hello.txt
"/Users/mtemkit/Desktop/java/javatutorial/hfiles/hello.txt"
File "/Users/mtemkit/Desktop/java/javatutorial/hfiles/hello.txt" not found
/Users/mtemkit/Desktop/java/javatutorial
/Users/mtemkit/Desktop/java/javatutorial/hfiles
twice1911.txt
"/Users/mtemkit/Desktop/java/javatutorial/hfiles/twice1911.txt"
File "/Users/mtemkit/Desktop/java/javatutorial/hfiles/twice1911.txt" not found