-
June 12th, 2008, 01:06 PM
#1
Member
Java Buffered Stream
Hi Guys,
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;
BufferedInputStream bis=new BufferedInputStream(new FileInputStream(strFrmFile));
BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(strToFile));
intBytRd=bis.read(bytBuf,0,1024);
while(!(intBytRd<0)){
bos.write(bytBuf,0,intBytRd);
intOfst+=intBytRd;
intBytRd=bis.read(bytBuf,0,1024);
}
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
#2
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.
Cheers,
ac
Similar Threads
-
By cgkanchi in forum The Security Tutorials Forum
Replies: 13
Last Post: February 8th, 2005, 03:39 PM
-
By SDK in forum Miscellaneous Security Discussions
Replies: 15
Last Post: November 26th, 2004, 04:50 AM
-
By MrLinus in forum Cosmos
Replies: 4
Last Post: April 18th, 2004, 08:01 AM
-
By dstevens1958 in forum AntiOnline's General Chit Chat
Replies: 2
Last Post: August 13th, 2003, 01:32 AM
-
By Remote_Access_ in forum Security Archives
Replies: 4
Last Post: January 3rd, 2002, 11:11 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|