Corrupted JPEG: DataInput/OutputStream

Discussion in 'Java' started by Timo Nentwig, Jun 6, 2004.

  1. Timo Nentwig

    Timo Nentwig Guest

    Hi!

    I download a JPG and write it to disk; this is rather old code which
    certainly worked. The only thing I'm aware of that changed is JDK 1.4 ->
    1.5b2. The written file is corrupt:

    URL u = new URL ("http://foo/bar.jpg");
    DataInputStream in = new DataInputStream
    (u.openConnection().getInputStream());

    File f = new File (foo);
    FileOutputStream fs = new FileOutputStream (f);
    DataOutputStream out = new DataOutputStream (fs);

    for (int b; (b = in.read ()) != -1;)
    {
    out.write (b);
    }

    in.close();
    fs.close();
    out.close();


    What's wrong? And, can I repair the corrupt files?
    Timo Nentwig, Jun 6, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. brrrdog
    Replies:
    0
    Views:
    826
    brrrdog
    Jul 9, 2003
  2. Jenny

    Response.OutputStream

    Jenny, Aug 4, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    9,438
    vMike
    Aug 4, 2003
  3. Replies:
    2
    Views:
    3,591
  4. lovaspillando
    Replies:
    0
    Views:
    1,023
    lovaspillando
    Aug 26, 2007
  5. Ivan Alameda Carballo
    Replies:
    0
    Views:
    487
    Ivan Alameda Carballo
    Aug 26, 2007
Loading...

Share This Page