package url;
import java.net.*;
import java.io.*;
public class Downloadphoto2
{
static String str="http://www.gdut.edu.cn/newgdut/images/8.gif";
static URL url;
public static void main(String args[])
{
try
{
url=new URL(str);
ObjectInputStream in=new ObjectInputStream(url.openStream());
FileOutputStream out=new FileOutputStream("D:\\downloadphoto.gif");
File file=(File)in.readObject();
FileInputStream fin=new FileInputStream(file);
byte b[]=new byte[1];
while(fin.read()!=-1)
{
fin.read(b);
out.write(b);
}
out.flush();
fin.close();
out.close();
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
catch(IOException e){}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
}
}
import java.net.*;
import java.io.*;
public class Downloadphoto2
{
static String str="http://www.gdut.edu.cn/newgdut/images/8.gif";
static URL url;
public static void main(String args[])
{
try
{
url=new URL(str);
ObjectInputStream in=new ObjectInputStream(url.openStream());
FileOutputStream out=new FileOutputStream("D:\\downloadphoto.gif");
File file=(File)in.readObject();
FileInputStream fin=new FileInputStream(file);
byte b[]=new byte[1];
while(fin.read()!=-1)
{
fin.read(b);
out.write(b);
}
out.flush();
fin.close();
out.close();
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
catch(IOException e){}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
}
}
while(fin.read()!=-1)
{
fin.read(b);
out.write(b);
}这里错了吧,是不是应该修改为下面这样while(fin.read(b)!=-1)
{
out.write(b);
}