OK now we have got some code:
First of all - let's break the static main function. This is common and should be first thing to do:
public class Main{
public Main(){
}
public static void main(String[] args) {
new Main();
}
}
Now we are able to use non static code.
The first part is good! You are reading the files in the folder.
After that it get's a bit wired - I assume you tested some things.
I added a foreach loop to browse through the files found in the folder.
Also the path to the files in the folder had to be set up correctly.
Now you can search in the files.
The StringTokenizer still fails! I did not correct that - cause I want you to figure that out.
You will find the error quite fast when you set up a break point on the Exception (click on the link in the console, that will set a break point that you can debug).
If you have any more questions, please feel free to ask.
Have fun.
public class Main {
public Main(){
String path = "C:/repositories";
File folder = new File(path);
System.out.println("Reading files under the folder " + folder.getAbsolutePath());
if (folder.isDirectory()) {
String directory[] = folder.list();
for (String directoryName : directory) {
System.out.println(directoryName);
}
}
for (String file : folder.list()) {
System.out.println("This is the file " + file);
File f = new File(path + "/" + file);
System.out.println("The path is " + f.getAbsolutePath());
FileInputStream fs = null;
InputStreamReader in = null;
BufferedReader br = null;
StringBuffer sb = new StringBuffer();
String textinLine;
try {
fs = new FileInputStream(f);
in = new InputStreamReader(fs);
br = new BufferedReader(in);
while (true) {
textinLine = br.readLine();
if (textinLine == null)
break;
sb.append(textinLine);
}
String textToEdit1 = "Fleo0012";
int cnt1 = sb.indexOf(textToEdit1);
sb.replace(cnt1, cnt1 + textToEdit1.length(), "Fleo0013");
fs.close();
in.close();
br.close();
}
catch (FileNotFoundException e) { e.printStackTrace();}
catch (IOException e) { e.printStackTrace();}
try {
FileWriter fstream = new FileWriter(f);
BufferedWriter outobj = new BufferedWriter(fstream);
outobj.write(sb.toString());
outobj.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
new Main();
}
}