• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • Mikalai Zaikin

downloading images?

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to know how to download images from a web site to my computer using i/o (or a better way if one is known). Using the available input and output streams my pictures end up, well, not like they used to be. Any help is much appreciated.
 
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Post some of your I/O code here so we can see what you're trying to attempt. I'm assuming this is a JAVA application rather than an applet, since an applet severly restricts I/O due to security. Unless it's a trusted applet.
-Peter
 
Noah Carroll
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This is my code. The URL is created here because 'url' is a string previous to this code. I know this does not work on images becuase of the way they are made, but I can't think of how else to do it. Thanks
 
Peter Tran
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Noah,
The problem with your code is you're using a Reader/Writer stream which is meant to read character (i.e. text) streams rather than a binary stream. Change your code to use BufferedInput/BufferedOutput stream.
-Peter
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to use InputStream/OutputStream or BufferInputStream/BufferOutputStream to read or write image files
try floowing code:
readImage(InputStream from, OutputStream to)
{
BufferedInputStream from = new BufferedInputStream(from);
BufferInputStream to = new BufferedOutputStream(to);
int c;
byte buf[] = new byte[2048];
try
{
System.out.println("read the other files!\n");
while((c=from.read(buf)) > -1)
{
to.write(buf);
to.flush();
}
}
catch (EOFException e) {}
catch (Exception e){}
}

 
reply
    Bookmark Topic Watch Topic
  • New Topic