Saving images

M

Marcelo

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
 
A

Andrew Thompson

Marcelo said:
How can I use the StreamInput and the StreamOutput

Huh? Are they new to Java 1.6? I don't see them here..
.. classes in order to
save images from an URL to the user directory?

suppose I have:
URL imageURL = getURL(image);

.........?

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?
 
T

Thomas Fritsch

Marcelo said:
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();
 
T

Thomas Fritsch

Marcelo said:
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.
 
R

Roedy Green

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top