I created a new class called “Tools” inside my “com.example.hello” workspace.
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;
}
}
From that exact namespace (com.example.hello), there is a .java file in there…and I want to use getSource.
I tried import com.example.hello.Tools.*
But for some reason, I can’t use getSource?
I just want to be able to call “getSource” from my other classes that are in the same folder.
You want:
to use
getSource()without writingTools.getSource(). Of course if you want to writeTools.getSource()just use a standardimport: