我在“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