You'd have to detect it manually. Once you have done so, to obtain a resource from the classpath in the form of an inputstream:
class Example {
void foo() {
try (InputStream in = Example.class.getResourceAsStream("/config.cfg")) {
// use here. It'll be null if not found.
}
}
}
NB: Without the leading slash, it's relative to the same directory (within the jar if need be) that contains your Example.class
file. With the leading slash it is relative to the root of the classpath (the root of the jar, the root of your 'bin' dir, etc).
Naturally, there is no way to get an outputstream; as a rule, most entries in the classpath aren't writable.