Today in the development of a Java project, requires reading the information in the configuration file, began to write the absolute path, when the project hit jar package will not find the configuration file, back in the online when a method, the problem finally solved, take out to share with you.
public class Smbconfig {
SMB Message Parameters
public static String Smb_sender = ""; SMB Message Sender
public static String Smb_exchange = ""; SMB Message Group
public static String Smb_serverip = ""; SMB Server-side IP
public static String Smb_serverport = ""; SMB Service port number
static {
InputStream in = SMBConfig.class.getClass (). getResourceAsStream ("/config/config.properties");
Properties P = new properties ();
try {
P.load (in);
} catch (IOException e) {
E.printstacktrace ();
}
SMB Message Parameters
Smb_sender = P.getproperty ("Smb.sender"). ToString (). Trim ();
Smb_exchange = P.getproperty ("Smb.exchange"). ToString (). Trim ();
Smb_serverip = P.getproperty ("Smb.smbserip"). ToString (). Trim ();
Smb_serverport = P.getproperty ("Smb.smbserport"). ToString (). Trim ();
}
}
Solve the problem of the path of the configuration file cannot be obtained after the project hits the jar package