Hi,
How can I use the StreamInput and the StreamOutput classes in order to
save images from an URL to the user directory?
suppose I have:
URL imageURL = getURL(image);
........?
thanks,]
Marcelo
Andrew Thompson - 30 Sep 2005 13:33 GMT
> How can I use the StreamInput and the StreamOutput
Huh? Are they new to Java 1.6? I don't see them here..
<http://java.sun.com/j2se/1.5.0/docs/api/allclasses-frame.html>
>.. classes in order to
> save images from an URL to the user directory?
[quoted text clipped - 3 lines]
>
> .........?
If I supposed you had that little, I might suggest you
hire a Java programmer to do this for you.
So far, have you written anything that compiles and runs?
Are you familiar with the JavaDocs and the Java tutorial?
Is this in an applet (most difficult) or an application?
Thomas Fritsch - 30 Sep 2005 14:10 GMT
> How can I use the StreamInput and the StreamOutput classes in order to
> save images from an URL to the user directory?
Eeeeh? You mean InputStream and OutputStream, don't you?
> suppose I have:
> URL imageURL = getURL(image);
>
> ........?
The solution is not specific for images, it is the same for any URL:
InputStream input = url.openStream(imageUrl);
OutputStream output = new FileOutputStream("localFileName");
//... read bytes from input until EOF, write bytes to output
input.close();
output.close();

Signature
"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')
Thomas Fritsch - 30 Sep 2005 14:12 GMT
> InputStream input = url.openStream(imageUrl);
Ooops, I meant:
InputStream input = imageUrl.openStream();

Signature
Thomas
Marcelo - 30 Sep 2005 14:57 GMT
Thanks a lot,
It will help me a little.
However I have another problem. whenever I have a URL like this:
www.whatever.com/jni/images/im.gif
How Can I have the directory
www.whatever.com/jni/images
without doing regex stuff?
and what about a :
www.whatever.com/jni
Everything done with the original imageURL =
www.whatever.com/jni/images/im.gif ??????????
thanks a lot
Marcelo
Thomas Fritsch - 30 Sep 2005 15:29 GMT
> However I have another problem. whenever I have a URL like this:
>
> www.whatever.com/jni/images/im.gif
This is not a legal URL. You probably mean
http://www.whatever.com/jni/images/im.gif
or more exactly the constructed URL object:
new URL("http://www.whatever.com/jni/images/im.gif")
> How Can I have the directory
>
> www.whatever.com/jni/images
Class java.net.URL has some handy methods (described in the API doc) for
getting the parts: getProtocol(), getHost(), getPath(), ...
Choose what you need.
> without doing regex stuff?
Don't break a fly on the wheel. String.index('/') and
String.substring(...) will be sufficient.

Signature
"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')
Marcelo - 30 Sep 2005 16:19 GMT
Roedy Green - 30 Sep 2005 22:53 GMT
>How can I use the StreamInput and the StreamOutput classes in order to
>save images from an URL to the user directory?
>
>suppose I have:
>URL imageURL = getURL(image);
An image is just a file of bytes if you don't try to display it or
modify it. The FileTransfer class will do it for you, which would
handle humongous images.
see http://mindprod.com/products1.html#FILETRANSFER
For a small image just read it into ram and write it to disk.
See http://mindprod.com/applets/fileio.html
for how. Tell it you are dealing with raw bytes.
j

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.