When you write a certificate request, you encounter the need to go under the absolute path to find the certificate
The absolute path of the current class in MyEclipse is thus obtained:
Package Fafa;
public class Test {
private static String Currentdir = null;
public static void Main (string[] args) {
Currentdir = Test.class.getResource (""). GetPath ();
if (!currentdir.endswith ("/")) {
Currentdir + = "/";
}
System.out.println (Currentdir);
}
}
In idea, the result of this is not the result of the current class, but the path of the current class through the compiled paths, that is to say, the target/classes
How do you get the absolute path of the current class in idea?
The following method can satisfy the demand,
To get the path of the current class is simply to read the file, we can do this:
InputStream fikeyfile = CryptNoRestrict.class.getResourceAsStream ("/" +currentdir);The Currentdir in the code is the name of the file, for example: text.pfx
This allows you to look directly into the file and then convert it to the form of the stream
As for how to get when the class path is not loaded, temporarily not clear, next supplement.