• Post Reply Bookmark Topic Watch Topic
  • New Topic

downloading images?  RSS feed

 
Noah Carroll
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • 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.
 
Peter Tran
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
John McWon
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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){}
}

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!