import java.io.*;
import java.net.*;
public class SaveImage {
public static void main(String args[]) {
DataInputStream di = null;
FileOutputStream fo = null;
byte [] b = new byte[1];
try {
// input
URL url = new URL(args[0]);
URLConnection urlConnection = url.openConnection();
urlConnection.connect();
di = new DataInputStream(urlConnection.getInputStream());
// output
fo = new FileOutputStream(args[1]);
// copy the actual file
// (it would better to use a buffer bigger than this)
while(-1 != di.read(b,0,1)) {
fo.write(b,0,1);
}
di.close();
fo.close();
}
catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
System.out.println("done.");
}
}
二、运行方法,如:
C:\java>java SaveImage http://www.java3z.com/cwbwebhome/images/logo.gif logo.gif
done.
</td>
<td width="170" valign="top">
</td>
</tr>
<tr>
<td height="20" colspan="2"></td> </tr> </table> </td> </tr> <tr>
↑返回目录
前一篇: 将数据库操作封装到Javabean
后一篇: 怎样制作*_zh_CN.properties中文资源文件