First, you need a class loader. Secondly, you need to replace the dots . to the class name with forward slashes / and the suffix of the .class extension to identify the real path.
So this should work:
String name = String.class.getName().replace(".", "/") + ".class"; URL url = Thread.currentThread().getContextClassLoader().getResource(name); InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream(name);
Edit: I had to add, inputStream.available() not a way to find out the file size. It simply returns the number of bytes that can be read without blocking. In other words, the return value should never be considered consistent. If you want to get the actual length, you really need to read the entire stream.
source share