Creato da pastuweb.com
Share My Page
My Social Accounts
Account FaceBook Account LinkedIn Account Twitter Account Google Plus Account Git Hub

Example:


String nomeFile = new String("pippo");

System.out.println("idFile: "+nomeFile+" NON ESISTE");
BufferedOutputStream bos = null;
byte[] fileArray = service.getFileMisura(nomeFile);
System.out.println("fileArray: "+fileArray.length);
BufferedInputStream in = new BufferedInputStream(new ByteArrayInputStream(fileArray));
FileOutputStream fos;
fos = new FileOutputStream("/tmp/"+nomeFile+".tmp");
bos = new BufferedOutputStream(fos);
int byte_;
while ((byte_ = in.read()) != -1){
      bos.write(byte_);//scrive
}
/**** begin IMPORTANT PART *******/
in.close();
bos.flush();

fos.flush();
bos.close();
fos.close();
/**** end IMPORTANT PART *******/
System.out.println("Close All");


Why did I write "IMPORTANT PART"?
Because if input file or byte array is very very small, if you don't flush and close the stream and buffer, the file that you have created in /tmp/ folder will be EMPTY = 0 byte.

So flush() and close() methods are very importants.
Average (1 Vote)
The average rating is 5.0 stars out of 5.