My interest in piqued I wrote this little test:
public static void main(String[] args) throws IOException { FileInputStream fileInputStream = new FileInputStream("/home/nick/foo"); FileOutputStream fileOutputStream = new FileOutputStream("/home/nick/bar"); fileOutputStream.write(fileInputStream.read()); fileOutputStream.flush(); fileOutputStream.close(); fileInputStream.close(); }
It worked as expected - read one byte from /home/nick/foo and wrote it in /home/nick/bar
EDIT:
Updated program:
public static void main(String[] args) throws IOException { FileInputStream fileInputStream = new FileInputStream("/home/nick/foo"); FileOutputStream fileOutputStream = new FileOutputStream("/home/nick/bar"); while (fileInputStream.available()>0) { fileOutputStream.write(fileInputStream.read()); } fileOutputStream.flush(); fileOutputStream.close(); fileInputStream.close(); }
I copied the entire file. (note - I would not recommend copying a file byte at a time, use buffered I / O classes to copy entire fragments)
Have you accidentally forgotten flush() and close() for OutputStream?
source share