In my program, I have to overwrite the current data to a CSV file. But after being overwritten, when I launch my program again, those data disappeared.
> public class writeFile {
private Writer fw;
public writeFile(String fileName) {
try {
fw = new FileWriter(fileName, false);
} catch (IOException e) {
System.out.println(e.toString());
}
}
public void writeToCSV(String[] org) {
String text = "";
for(int i = 0; i < org.length; i++) {
text += org[i];
if(i != org.length - 1) {
text += ",";
} else {
text += "n";
}
}
try {
fw.write(text);
fw.flush();
//fw.close();
} catch (IOException e) {
System.out.println(e.toString());
}
}
public void shutDown() {
try {
fw.close();
} catch(IOException e) {
System.out.println(e.toString());
}
}
}
Above is my writeFile class. Can anyone help me to explain and fix it?
New contributor
allmight is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.