评论正解public ArrayList translate(ArrayList list) {
if (list.size() >= 3) {
list.set(0, "");
list.set(1, "");
list.set(2, "");
}
return list;
}
public void writeFile(ArrayList list, String path) {
BufferedWriter bw = null;
try {
File file = new File(path);
if (!file.exists()) file.createNewFile();
bw = new BufferedWriter(new FileWriter(file));
StringBuffer sb = new StringBuffer();
Iterator it = list.iterator();
while(it.hasNext()) {
sb.append(it.next()+"\n");
}
list.clear();
bw.write(sb.toString());
bw.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (bw != null) bw.close();
bw = null;
} catch (IOException e) {}
}
}