請問有關於下載class問題 |
尚未結案
|
lichun1228
一般會員 發表:16 回覆:17 積分:11 註冊:2003-12-14 發送簡訊給我 |
以下是我寫的原始碼 我雖然能夠把class下載 但是這class卻不能夠執行
不知是那裡有錯 請教各位高手 /* URLClient.java*/
import java.net.*;
import java.lang.reflect.*;
import java.io.*;
public class URLClient {
public static void main(String args[]) throws Exception {
URL u = new URL("http://192.168.18.53/new/abc.class");
URLConnection uc = u.openConnection();
BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream()));
String str="";
StringBuffer st = new StringBuffer();
while ((str= br.readLine())!= null) {
st.append(str "\n");
}
br.close();
String s1 = st.toString();
FileOutputStream fos = new FileOutputStream("abc.class");
try{
fos.write(s1.getBytes());
fos.close();
}
catch(IOException e){System.out.println("IOException");}
}
}
|
neoart
版主 發表:22 回覆:582 積分:425 註冊:2003-05-09 發送簡訊給我 |
引言: 以下是我寫的原始碼 我雖然能夠把class下載 但是這class卻不能夠執行 不知是那裡有錯 請教各位高手 /* URLClient.java*/ import java.net.*; import java.lang.reflect.*; import java.io.*; public class URLClient { public static void main(String args[]) throws Exception { URL u = new URL("http://192.168.18.53/new/abc.class"); URLConnection uc = u.openConnection(); BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream())); String str=""; StringBuffer st = new StringBuffer(); while ((str= br.readLine())!= null) { st.append(str "\n"); } br.close(); String s1 = st.toString(); FileOutputStream fos = new FileOutputStream("abc.class"); try{ fos.write(s1.getBytes()); fos.close(); } catch(IOException e){System.out.println("IOException");} } }你這樣做只是下載罷了 要用class loader,載入之後,用instance的方式建立實體才可以執行. 參考: http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ClassLoader.html |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |