On Tue, Jul 28, 2009 at 11:02 PM, Fernando Cabredo<[email protected]> wrote: > I have the code below which lists files under a folder node and copy the > files into my c:\ drive. However, I am not getting right the use of > InputStream and FileOutputStream.this is why the file that is being copied > into my c:\ is incorrect. > ... > attachFileIS = attachFileValue.getStream(); > fout = new FileOutputStream("c://"+nodename); > byte[] readData = new byte[1024]; > int i = attachFileIS.read(readData); > while (i != -1) { > fout.write(i); > i = attachFileIS.read(readData); > } > fout.close();
I would suggest to use Apache commons-io [1] for those things. It has IOUtils.copy() for copying from an Input to an OutputStream [2] (and many other useful methods). [1] http://commons.apache.org/io/ [2] http://commons.apache.org/io/api-1.4/org/apache/commons/io/IOUtils.html#copy(java.io.InputStream,%20java.io.OutputStream) Regards, Alex -- Alexander Klimetschek [email protected]
