http

R

ruinadream

this code can save html source in a directory of my pc but can't save images!
If i introduce image path this class save it but I can't see it as jpeg or gif!
How can I do it, all in a 1 step!
thank you very much
Andrea

import java.net.*;
import java.io.*;
import java.util.*;

public class getPage1
{
public void download(String arg)
{
String un;
un=arg;


System.out.println("URL:"+un);

URL url;

try {
url= new URL(un);
}
catch (MalformedURLException e)
{
System.out.println("URL errato");
url = null;
};


BufferedReader stream;
try {
stream = new BufferedReader (new InputStreamReader (url.openStream()));
}
catch (IOException e)
{
System.out.println("Errore di apertura del file"+e);
stream=null;
System.exit(0);
};

File out=new File("/Pagine disponibili/" + url.getFile());

FileWriter Output;

try {
Output=new FileWriter(out);
}
catch (IOException e)
{
Output=null;
};

String l;
try
{
while ((l=stream.readLine())!=null)
{
Output.write(l);
};
Output.flush();
Output.close();
}
catch (IOException e)
{
System.out.println("Errore di lettura.");
};
}

}
 
A

Aleksander =?iso-8859-2?Q?Str=B1czek?=

ruinadream said:
this code can save html source in a directory of my pc but can't save images!
If i introduce image path this class save it but I can't see it as jpeg or gif!
How can I do it, all in a 1 step!

[cut]
*Reader and *Writer classes are for character streams.
For binary streams use *InputStream and *OutputStream.
* means File, Buffered, etc.

Read
http://java.sun.com/j2se/1.4.2/docs/api/java/io/Reader.html
http://java.sun.com/j2se/1.4.2/docs/api/java/io/Writer.html
http://java.sun.com/j2se/1.4.2/docs/api/java/io/InputStream.html
http://java.sun.com/j2se/1.4.2/docs/api/java/io/OutputStream.html
 

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,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top