Java IO transfer issue -
a fileutils class created re-use io. transfer files (random amount) on share 1 unix server another.
my issue: @ random 1 file come through 0kb file, no exceptions , says transferred successfully.
basic method use:
resultcode = 0; fileinputstream fis = null; fileoutputstream fos = null; try { fis = new fileinputstream(filelocation + orginalfile); fos = new fileoutputstream(tofolder + destinationfile); byte[] buf = new byte[1024]; int = 0; while ((i = fis.read(buf)) != -1) { fos.write(buf, 0, i); } resultcode = 1; } catch (exception e) { resultcode = 2; //our logging } { try { fis.close(); fos.close(); } catch (exception e) { //our logging } } return resultcode; } any ideas on can causing this? fileutils class called each time individual file transfer.
thank you
flush file output stream before closing fos.flush(), not sure solve problem worth try:
public void flush() throws ioexception
flushes output stream , forces buffered output bytes written out. general contract of flush calling indication that, if bytes written have been buffered implementation of output stream, such bytes should written intended destination.
Comments
Post a Comment