Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6697057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:24:54+00:00 2026-05-26T06:24:54+00:00

I download a picture from a URL with the following method : private void

  • 0

I download a picture from a URL with the following method :

private void download(String srcUrl, String destination) throws Throwable {
    File file = new File(destination);
    if (!file.exists()) {
        file.createNewFile();
        BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
        BufferedInputStream in = new BufferedInputStream(new URL(srcUrl).openStream());
        byte bytes[] = new byte[1024];
        while (0 <= in.read(bytes, 0, 1024)) {
            out.write(bytes);
        }
        out.close();
        in.close();
    }
}

On windows the resulting picture is a perfect copy of the original. However on my debian server, the picture is altered: the bottom right area of the picture is blur. It happens on every picture, and it is always on the same area of the picture.

Thanks a lot for any help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:24:54+00:00Added an answer on May 26, 2026 at 6:24 am

    I don’t know why the result are different between systems, although the code is flawed and I suspect it has something to do with the observed behavior.

    while (0 <= in.read(bytes, 0, 1024)) {
        out.write(bytes);
    }
    

    Should be:

    int count;
    while ((count = in.read(bytes, 0, 1024)) > 0) {
        out.write(bytes, 0, count);
    }
    

    Otherwise there is a [high] chance “garbage” is written at the end which might explain the blurriness, depending on the program that tries to view the [corrupted] image file. (The size of the array used as the buffer does not change — should only write out as much data as was written to it.)

    Happy coding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to download af picture with http.get(string), where the string is the url.
I download an image from an URL asynchronously using WebRequest this way: public void
I try to download a picture from URL to SD card/Download. And I try
I am trying to download image from HTTP URL to my computer via c#.
I'm trying to download users profile picture from facebook in PHP using this function
Hy! I download a picture from the internet and want to display it. The
I'm download jpeg picture from web server and load it to UIImage. If I
So I am trying to write a script to download a picture file with
We want to allow a user to download a picture via a button from
I want to download this picture using Ruby. How do I do that? http://farm1.static.flickr.com/92/218926700_ecedc5fef7_o.jpg

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.