I'm not aware of a command-line tool that you can use for this, though that doesn't mean one doesn't exist. However, you can write a quick utility program to get the contents of the resource in less than 20 lines of code.
Note all three approaches demonstrated, as currently implemented, read the resource from the JDK which is executing the program. Also, you can obviously modify the code of either approach to better fit your needs. Perhaps by making them more "dynamic" (e.g., accept command-line arguments).
Use Resource API
One option is to use the resource API:
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
var name = "/sun/net/www/content-types.properties";
try (var in = Object.class.getResourceAsStream(name)) {
// Thanks to Holger for the code simplification
in.transferTo(System.out);
}
}
}
Note: The getResourceAsStream method is being called on a class that's in the java.base module.
Then you'd run the above like so (making use of the "single source file" feature):
java --add-opens=java.base/sun.net.www=ALL-UNNAMED Main.java
Use ModuleReader
import java.io.IOException;
import java.lang.module.ModuleFinder;
public class Main {
// Thanks to Holger for pointing out this approach
public static void main(String[] args) throws IOException {
var name = "sun/net/www/content-types.properties";
var mod = ModuleFinder.ofSystem().find("java.base").orElseThrow();
try (var reader = mod.open();
var in = reader.open(name).orElseThrow()) {
in.transferTo(System.out);
}
}
}
With this approach, you don't need the --add-opens argument.
Use JRT File System
A third option is to use the JRT file system and read the resource like a "file":
import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
public class Main {
public static void main(String[] args) throws IOException {
var uri = URI.create("jrt:/java.base/sun/net/www/content-types.properties");
try (var in = Files.newInputStream(Path.of(uri))) {
// Thanks to Holger for code simplification
in.transferTo(System.out);
}
}
}
With this option, you don't need the --add-opens argument.