java.io.FileNotFoundException: EIF.properties (The system cannot find
the file s
pecified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:91)
at java.io.FileInputStream.<init>(FileInputStream.java:54)
at config.LoadProperties.load(LoadProperties.java:24)
at snmpManager.GetClass.main(GetClass.java:73)
Why?
Thanks
it's difficult to say without the code.
1. Is the LoadProperties class in the jar? I think yes
2. is the properties-File in same package like the
LoadProperties-class?
3. You should use the getResourceAsStream-Method.
Similar to that:
public static void main(String[] args) {
InputStream in = this.getClass.getClassLoader("EIF.properties");
}
You can also use the getClass.getResourceAsStream, but if you use that,
the Loader will search the File in the Package (see also API for
Class.getResourceAsStream and Classloader.getResourceAsStream());
Greetings
Joe
1. Yes
2. No,properties file is out of package of LoadProperties-class; but if
it run with eclipse, it function correctly!
3.this is code of LoadProperties-class
package config;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import snmpManager.GetClass;
import udp.SenderUdp;
public class LoadProperties {
public LoadProperties(){
}
public void load(){
Properties myProp = new Properties();
// load key-value pairs from a file
FileInputStream fis;
try {
fis = new FileInputStream("EIF.properties");
myProp.load(fis);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// Getting values from the loaded key-value pairs is done
// by calling getProperty on the Properties Object
String myPortAgent = "PORT_NUMBER_AGENT";
String myIpAddressAgent = "IPADDRESS_AGENT";
String myMibDirectoryAgent = "MIB_DIRECTORY";
String myPortUdp = "PORT_NUMBER_CCFH1";
String myIpAddressUdp = "IPADDRESS_CCFH1";
// Use this key to get the corres. value as a **String**
// if the key does not exist, myValue will be null
String myPortValue = myProp.getProperty(myPortAgent);
String myIpValue = myProp.getProperty(myIpAddressAgent);
String myMibValue = myProp.getProperty(myMibDirectoryAgent);
GetClass.setPort(myPortValue);
GetClass.setHost(myIpValue);
GetClass.setMib(myMibValue);
String myPortUdpValue = myProp.getProperty(myPortUdp);
String myIpUdpValue = myProp.getProperty(myIpAddressUdp);
SenderUdp.setPort(myPortUdpValue);
SenderUdp.setHost(myIpUdpValue);
}
}
what do you think?
thanks
--
"TFritsch$t-online:de".replace(':','.').replace('$','@')