मैं प्रॉपर्टी को डेटा लिखने के लिए कोड निम्न का उपयोग कर रहा फ़ाइलगुण फ़ाइल में मौजूदा डेटा में नया डेटा कैसे जोड़ना है?
public void WritePropertiesFile(String key, String data)
{
Properties configProperty = new Properties();
configProperty.setProperty(key, data);
File file = new File("D:\\Helper.properties");
FileOutputStream fileOut = new FileOutputStream(file,true);
configProperty.store(fileOut, "sample properties");
fileOut.close();
}
I am calling the above method 3 times as follows:
help.WritePropertiesFile("appwrite1","write1");
help.WritePropertiesFile("appwrite2","write2");
help.WritePropertiesFile("appwrite3","write3");
हालांकि, Helper.properties फ़ाइल में डेटा इस प्रकार प्रदर्शित होता है:
#sample properties
#Mon Jul 01 15:01:45 IST 2013
appwrite1=write1
#sample properties
#Mon Jul 01 15:01:45 IST 2013
appwrite2=write2
appwrite1=write1
#sample properties
#Mon Jul 01 15:01:45 IST 2013
appwrite3=write3
appwrite2=write2
appwrite1=write1
मैं मौजूदा डेटा को संलग्न करने के लिए डेटा चाहते हैं और डुप्लिकेट डेटा नहीं चाहता है, जो निम्नानुसार है:
appwrite3=write3
appwrite2=write2
appwrite1=write1
कृपया सुझाव दें कि यह कैसे करें?
हाय fge, धन्यवाद जवाब के लिए ... मैं कोड आप उल्लेख किया है की कोशिश की, यह है अच्छा कर रहा है। लेकिन मुझे एक समस्या मिली जब मैं अन्य वर्ग फ़ाइल से विधि का उपयोग कर रहा हूं। मैं उपरोक्त फ़ंक्शन को एक वर्ग फ़ाइल से निम्नानुसार कॉल कर रहा हूं: help.WritePropertiesFile ("appwrite1", "write1"); help.WritePropertiesFile ("appwrite2", "write2"); help.WritePropertiesFile ("appwrite3", "write3"); – Vikas
यह एक और समस्या पूरी तरह से है;) आप इसके साथ मदद के लिए पर्याप्त कोड नहीं दिखाते हैं। अन्य कक्षा फ़ाइल से – fge
मैं निम्नानुसार कॉल कर रहा हूं: help.WritePropertiesFile ("appwrite4", "write4"); help.WritePropertiesFile ("appwrite5", "write5"); help.WritePropertiesFile ("appwrite6", "write6"); आउटपुट के रूप में appwrite4 = write4 appwrite5 = write5 appwrite6 = write6 यह डेटा Class1 से लिखा दूर करने और class2 इसकी जगह दिखाई देती है ... _Please मुझे पता डेटा दोनों वर्ग फ़ाइलों से लिखा स्टोर करने के लिए कैसे करते हैं ? – Vikas