Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2007

    Lightbulb 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.

    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));
    		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

  2. #2
    Custom User
    Join Date
    Oct 2001
    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.


Similar Threads

  1. Writing a port scanner in Java
    By cgkanchi in forum The Security Tutorials Forum
    Replies: 13
    Last Post: February 8th, 2005, 02:39 PM
  2. Java flaw could lead to Windows, Linux attacks
    By SDK in forum Miscellaneous Security Discussions
    Replies: 15
    Last Post: November 26th, 2004, 03:50 AM
  3. Men speak C, Women speak Java.
    By MrLinus in forum Cosmos
    Replies: 4
    Last Post: April 18th, 2004, 08:01 AM
  4. Confused about Java
    By dstevens1958 in forum AntiOnline's General Chit Chat
    Replies: 2
    Last Post: August 13th, 2003, 01:32 AM
  5. Difference between Java and JavaScript
    By Remote_Access_ in forum Security Archives
    Replies: 4
    Last Post: January 3rd, 2002, 10: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

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.