這個方法接收2個參數,例如一個網絡上的圖片,和你要保存圖片的地址.
public boolean initPhoto(String photoUrl,String filePath) {
??try {
???URL? url = null;
???try {
???? url = new URL(photoUrl);
???} catch(Exception e) {
???? System.out.println("URL ERROR");
???? return false;
???}
???FilterInputStream in=(FilterInputStream) url.openStream();
???File fileOut=new File(filePath);
???FileOutputStream out=new FileOutputStream(fileOut);
???byte[] bytes=new byte[1024];
???int c;
???while((c=in.read(bytes))!=-1) {
????out.write(bytes,0,c);
???}
???in.close();
???out.close();
???return true;
??} catch(Exception e) {
???System.out.println("Error!");
???return false;
??}
?}
posted on 2006-08-07 11:00
我心依舊 閱讀(3681)
評論(11) 編輯 收藏