The below method is being called from various place in AsynTask. It is coded for Android. Getting ConcurrentModificationException. How to make this method thread safe
public static String saveJsonFile(File dir, String name, JSONObject data) {
final File file = new File(dir.getPath() + File.separator + name);
try {
file.createNewFile();
} catch (final IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
BufferedWriter printWriter = null;
try {
printWriter = new BufferedWriter(new FileWriter(file), 8192);
// printWriter = new PrintWriter(file);
if (data != null)
data.write(printWriter); // java.util.ConcurrentModificationException
........
........