我在「com.example.hello」工作區內創建了一個名爲「Tools」的新類。爲什麼我不能把我的功能放在另一個班級?
Tools.java:
public class Tools {
public static String getSource (String theurl) {
URL u;
InputStream is = null;
DataInputStream dis;
String s;
String ss = "";
try {
u = new URL(theurl);
is = u.openStream(); // throws an IOException
dis = new DataInputStream(new BufferedInputStream(is));
while ((s = dis.readLine()) != null) {
ss = ss + s;
}
} catch (MalformedURLException mue) {
} catch (IOException ioe) {
} finally {
try {
is.close();
return ss;
} catch (IOException ioe) {
}
}
return ss;
}
}
從這個確切的命名空間(輸入com.example.hello),書中有一個.java文件......我想使用的getSource。
我試圖import com.example.hello.Tools.*
但由於某些原因,我無法使用的getSource?
我只是想能夠從我在同一文件夾中的其他類調用「getSource」。
「但由於某種原因,我無法使用getSource?」我希望編譯錯誤消息告訴你爲什麼......但你沒有在你的問題中包括這個。 – 2010-02-16 00:57:50