В этом коде я получаю java.util.ConcurrentModificationException, метод находится в веб-сервисе и сначала читает файл и проверяет, есть ли в файле vakNaam. Затем он будет удален и файл будет перезаписан. Исключение выдается Exception2 (в печати)
@WebMethod
public boolean removeVak(String naam){
ArrayList<String> tempFile = new ArrayList<String>();
//Read the lines
boolean found = false;
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader("C:/vak.txt"));
String strLine;
while ((strLine = br.readLine()) != null){
tempFile.add(strLine);
}
}catch(Exception e){
System.out.println("Exception " + e);
}finally {
try {
if (br != null)
br.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
//Write the lines
BufferedWriter out= null;
try{
for(String s : tempFile){
String [] splitted = s.split(" ");
if(splitted[0].equals(naam)){
tempFile.remove(s);
found = true;
}
}
out = new BufferedWriter(new FileWriter("C:/vak.txt", false));
for(String s: tempFile){
out.newLine();
out.write(s);
}
out.close();
} catch (Exception e) {
System.out.println("Exception2 " + e);
return false;
}finally {
try {
if (out != null)
out.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
return found;
}