i have written the following piece of code. and although it compiles and does not throw an exception, when executed. it creates the file for the buffered output stream, but when i open the output file it is empty and no data has been written to it.
Code:
import java.io.*;
public class FileReader{
public static void main(String[] args) throws Exception{
String strFrmFile=args[0];
String strToFile="/Users/me/Desktop/FileReader/"+args[1];
byte bytBuf[]=new byte[1024];
int intOfst=0;
int intBytRd=0;
System.out.println("FileReader: "+strFrmFile+" copied to "+strToFile);
}
}
admittedly, i thought that i understood what the second argument of the read() and write() methods (i.e. the offset parameters) were for, but now I am not so sure, so i might not be using them correctly. i would be very greatful for any help.
thanks in advance,
- user0182
June 14th, 2008, 03:19 PM
gothic_type
I would imagine that you are calling read() and write() correctly (although I've not bothered checking). What you appear to be missing is a call to close(). If you don't close the file, it won't actually write anything to it (I think).
I'm sure that one caught me a few times when I first did file writing.