Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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){}
}

 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic