This is particularly important if you want to get the number of bytes of a resource loaded by the class loader: getClass().getResource("myFile").openConnection().getContentLength()