Hiii ... मैं getSystemResourceAsStream() का उपयोग कर इंटरेस्टस्ट्रीम क्लास ऑब्जेक्ट में गुण फ़ाइल की सामग्री प्राप्त करना चाहता हूं। मैंने नमूना कोड बनाया है। यह मुख्य() विधि का उपयोग करके अच्छी तरह से काम करता है, लेकिन जब मैं प्रोजेक्ट को तैनात करता हूं और सर्वर पर चलाता हूं, गुण फ़ाइल पथ प्राप्त नहीं किया जा सकता है ... इसलिए इनपुटस्ट्रीम ऑब्जेक्ट स्टोर शून्य मान।getSystemResourceAsStream() शून्य
नमूना कोड यहाँ है ..
public class ReadPropertyFromFile {
public static Logger logger = Logger.getLogger(ReadPropertyFromFile.class);
public static String readProperty(String fileName, String propertyName) {
String value = null;
try {
//fileName = "api.properties";
//propertyName = "api_loginid";
System.out.println("11111111...In the read proprty file.....");
// ClassLoader loader = ClassLoader.getSystemClassLoader();
InputStream inStream = ClassLoader.getSystemResourceAsStream(fileName);
System.out.println("In the read proprty file.....");
System.out.println("File Name :" + fileName);
System.out.println("instream = "+inStream);
Properties prop = new Properties();
try {
prop.load(inStream);
value = prop.getProperty(propertyName);
} catch (Exception e) {
logger.warn("Error occured while reading property " + propertyName + " = ", e);
return null;
}
} catch (Exception e) {
System.out.println("Exception = " + e);
}
return value;
}
public static void main(String args[]) {
System.out.println("prop value = " + ReadPropertyFromFile.readProperty("api.properties", "api_loginid"));
}
}
सामान्य श्रेणी की बजाय सिस्टम क्लासलोडर का उपयोग क्यों कर रहे हैं? – skaffman