Howdy yall.
I'm having problems with reading and writing files using java, It seems even though im calling fout.close(); the streams are not closing?, causing the file to not be written to the disk.
When i close the program, the file is then written to the disk.
Is there someway i can avoid this behaviour?. If it's trying to be more efficient in writing (eg one write instead of 30-50 small ones). Is there someway i can trigger this after the loop? rather than exiting my program.
It's a real shit if someone tries to use the files if the program hasn't been closed. A "indeterminate state" odf is made. It's workable but does not contain the data i wrote into it. It only updates once the program has closed.
You can see how much of a prick this is.
PS. im using truezip6.6
for(int i=0;i<valuemodel.getSize();i++){
progress=i*100/(valuemodel.getSize()-1);
jProgressBar1.setValue(progress);
System.out.print(progress);
System.out.println();
data currentdata = (data) valuemodel.getElementAt(i);
String Output= "/"+outdir+"/"+currentdata.surname+" "+currentdata.name+".odt";
File templatecontents = new File(template,"content.xml");
//This code copied the bulk of the file from template
try{
File foutall = new File(Output);
copy(template,(File) foutall);
}
catch(java.io.IOException e){
javax.swing.JOptionPane.showMessageDialog(EmailConverterGUI.this, "IOException #1. Creation of Output failed");
}
//This creates the new content.xml
try{
FileInputStream fin = new FileInputStream(templatecontents);
FileOutputStream fout = new FileOutputStream(Output+"/content.xml");
String str;
while((str= new DataInputStream(fin).readLine()) !=null){
str= replacetemplate(str,currentdata);
new DataOutputStream(fout).writeBytes(str);
}
fout.close();
fin.close();
fout.flush();
}
catch(java.io.IOException e){
javax.swing.JOptionPane.showMessageDialog(EmailConverterGUI.this, "IOException #2. Error creating content.xml");
e.printStackTrace();
}
}