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.");
};
}
}
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.");
};
}
}