public void saveList(Vector<Vector> table_data){
ArrayList<String> output_list = new ArrayList<String>();
for(int i=0;i<table_data.capacity();i++){
String temp="";
Vector tempVector = (Vector) table_data.elementAt(i);
tempVector.trimToSize();
for(int v=0;v<tempVector.capacity();v++){
temp+=((String)tempVector.elementAt(v))+" ";
}
temp = temp.trim();
System.out.println(temp);
output_list.add(temp);
}
BufferedWriter bw = null;
FileWriter fw = null;
try{
fw = new FileWriter(output_filename,false);
bw= new BufferedWriter(fw);
for(String i : output_list){
bw.write(i);
bw.newLine();
}
}
catch(FileNotFoundException e){}
finally{
if (bw != null) {
try {
bw.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
Here is my code rewriting a file. There is a JButton calling this function every time I click it. It passes vector from JTable. The file should always be overwritten. But it actually only overwrites when i first click the button. What is the issue and how can I solve it?