Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: I/O and byte arrays.

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    21
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default I/O and byte arrays.

    Solved the problem.
    Last edited by LDM91; March 3rd, 2011 at 02:18 PM. Reason: [SOLVED]


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: I/O and byte arrays.

    Do you have some code we could look at? It's difficult to diagnose the problem without it.

  3. #3

    Default Re: I/O and byte arrays.

    I don't understand your problem,but let's assume that we have those streams:
    in:the input stream from server
    out: the output stream to server
    outfile: the output stream to file.
    I suppose that you have already created them.
    now let's download that file:
    int i;//number of received bytes
    byte []data=new byte[100];//byte array to hold data
    //now:
    while((i=in.read(data))!=-1){
    outfile.write(data,0,i);
    outfile.flush();
    }
    in.close();
    outfile.close();
    out.close();

    the line :
    outfile.write(data,0,i); means : only write the bytes that I have just read and not more(those bytes are from 0 to i).
    I hope this may help you.

  4. #4
    Junior Member
    Join Date
    Oct 2010
    Posts
    21
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Re: I/O and byte arrays.

    Solved the problem.
    Last edited by LDM91; March 3rd, 2011 at 02:19 PM. Reason: [SOLVED]

  5. #5
    Junior Member
    Join Date
    Oct 2010
    Posts
    21
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Re: I/O and byte arrays.

    Solved the problem.
    Last edited by LDM91; March 3rd, 2011 at 02:19 PM. Reason: [SOLVED]

Similar Threads

  1. How Convert a Byte array to a image format
    By perlWhite in forum Algorithms & Recursion
    Replies: 7
    Last Post: February 19th, 2011, 03:16 PM
  2. UTF - 8 / Byte Stream
    By JavaCODER in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: October 16th, 2010, 02:26 PM
  3. [SOLVED] utf-16 byte[] to string conversion
    By Gerhardl in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 25th, 2010, 07:06 AM
  4. byte[] from vector
    By perlWhite in forum Collections and Generics
    Replies: 1
    Last Post: August 26th, 2009, 05:10 AM
  5. Convert Vector to Byte Array
    By perlWhite in forum Java Theory & Questions
    Replies: 0
    Last Post: August 25th, 2009, 05:45 AM