Ho utilizzazo il seguente codice per creare un file xls. Il problema è che dal momento che utilizzando un altro codice provo a leggere il file il file risulta essere sempre vuoto, anche se in realtà il foglio ed il suo contenuto è stato creato!!!!javascript:void(0);javascript:void(0);
Vi prego aiutatemi!!!!

package smsxls.utils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFDataFormat;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import java.util.Date;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import org.apache.log4j.Logger;
import org.apache.poi.hssf.util.HSSFColor;




public class fileXls {

private static Logger log = Logger.getLogger(fileXls.class);
private ArrayList namediga;
private ArrayList sub;
private ArrayList id;
private ArrayList generation_pattern;
private String namelivell;
private ArrayList cartella;
private ArrayList dir;
private String localSave;
private int numberDir;
private int numinsert;
private ArrayList metricCount;

public fileXls (ArrayList namediga,ArrayList sub,ArrayList id,ArrayList randomlivell,String namelivell,ArrayList cartella,ArrayList dir,String localSave,int numberDir,int numinsert,ArrayList metricCount)
{
this.namediga = namediga;
this.sub = sub;
this.id = id;
this.generation_pattern = randomlivell;
this.namelivell = namelivell;
this.cartella = cartella;
this.dir = dir;
this.localSave = localSave;
this.numberDir = numberDir;
this.numinsert = numinsert;
this.metricCount = metricCount;
}


public void creaFileXls() throws IOException
{
// path salvataggio file xls
String percorsoSave = (this.localSave)+"//"+this.cartella.get(1)+"//";
// Date-month-years-hour-minute
Date now = Calendar.getInstance().getTime();
// Formato ora
SimpleDateFormat pdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm");

Date d = new Date();
d.setTime(System.currentTimeMillis());
String data = sdf.format(d);
String datelivello = pdf.format(d);
int [] contatore_inserimenti = new int [this.numberDir];


for(int j=0;j<this.numberDir;j++)
{
int digheinserite = 0;
percorsoSave = (this.localSave)+this.cartella.get(1)+"//"+(this.dir).get(j)+"//";
String percorsosavefile = (percorsoSave+this.namelivell+datelivello+".xls"); //datelivello+".xls");

FileOutputStream fileOut = new FileOutputStream(percorsosavefile);


//Creo un Workbook e poi un foglio di lavoro

HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Foglio1");

// Ora creo una riga notare che sia le righe che le colonne si indirizzano con un numero

HSSFRow row = sheet.createRow(0);

//Dimensiono le colonne del foglio di lavoro

sheet.setColumnWidth(0, 6000);
sheet.setColumnWidth(1, 6000);
sheet.setColumnWidth(2, 6000);
sheet.setColumnWidth(3, 6000);

//Creazione delle celle di titolo

HSSFCell cella0 = row.createCell(0);
HSSFCell cella1 = row.createCell(1);
HSSFCell cella2 = row.createCell(2);
HSSFCell cella3 = row.createCell(3);

// impostazione dello stile della prima riga

HSSFCellStyle sty = wb.createCellStyle();
sty.setBorderBottom(HSSFCellStyle.BORDER_THIN);
sty.setFillForegroundColor(HSSFColor.GREY_25_PERCE NT.index);
sty.setFillPattern ( HSSFCellStyle.SOLID_FOREGROUND ) ;
sty.setAlignment(HSSFCellStyle.ALIGN_CENTER);
sty.setBorderLeft (HSSFCellStyle.BORDER_MEDIUM);
sty.setBorderRight( HSSFCellStyle.BORDER_MEDIUM );


// impostazione dello stile delle righe sucessive

HSSFCellStyle stile = wb.createCellStyle();
stile.setAlignment(HSSFCellStyle.ALIGN_CENTER);

// Stringhe da inserire nella prima riga

HSSFRichTextString diga = new HSSFRichTextString("DIGA");
HSSFRichTextString id = new HSSFRichTextString("Numero archivio");
HSSFRichTextString time = new HSSFRichTextString("ora/minuti rilevazione");
HSSFRichTextString livell = new HSSFRichTextString("livello invaso");

// Scrive nelle celle della prima riga

cella0.setCellValue(diga);
cella0.setCellStyle(sty);
cella1.setCellValue(id);
cella1.setCellStyle(sty);
cella2.setCellValue(time);
cella2.setCellStyle(sty);
cella3.setCellValue(livell);
cella3.setCellStyle(sty);


int i =0;
int s =0;

while (i<this.numinsert)
{
if (((this.namediga).get(i)).equals((this.dir).get(j) ))
{

int metric = Integer.parseInt((String) (this.metricCount).get(i));

if(metric!=0)
{
HSSFRow rows = sheet.createRow(s+1);

//Creazione delle celle diga,sub,data

HSSFCell cellaDiga = rows.createCell(0);
HSSFCell cellaSub = rows.createCell(1);
HSSFCell cellaData = rows.createCell(3);

//Creazione delle stringhe di testo

HSSFRichTextString dighe = new HSSFRichTextString((String) (this.namediga).get(i));
HSSFRichTextString idSub = new HSSFRichTextString((String) ((this.id).get(i))+((this.sub).get(i)));

// inserisci nella cella il nome della diga

cellaDiga.setCellValue(dighe);
cellaDiga.setCellStyle(stile);


// inserisci nela cella il sub

cellaSub.setCellValue(idSub);
cellaSub.setCellStyle(stile);

// inserisci nella cella la data

cellaData.setCellValue(new Date());
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setDataFormat(HSSFDataFormat.getBuiltinF ormat("m/d/yy h:mm"));
cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER) ;
cellaData = rows.createCell(2);
cellaData.setCellValue(new Date());
cellaData.setCellStyle(cellStyle);

String[] gpa = ((String)this.generation_pattern.get(i)).split("," );

if (gpa[0].equals("random"))
{
long min = Long.parseLong(gpa[1]);
long max= Long.parseLong(gpa[2]);
long random=min+Math.round(Math.random()*(max-min));
HSSFCell rd = rows.createCell(3);
rd.setCellValue(random);
rd.setCellStyle(stile);
}
s = s + 1;
digheinserite = digheinserite + 1;

}
}

i++;

}
contatore_inserimenti[j] = digheinserite;

// fileOut.flush();
wb.write(fileOut);
fileOut.close();



}

int somma = 0;
for (int i=0;i<this.numberDir;i++)
{
somma = somma + contatore_inserimenti[i];
}
if (somma == this.numinsert )
log.info("Tutte le dighe sono state inserite in xls "+somma);
else
{
log.info("Non sono state inserite in xls le dighe senza il livello di invaso");
log.info("Dighe inserite in xls " + somma);
}


}




}