Ragazzi, perfetto, con il metodo getResourceAsStream la lettura funziona perfettamente, senza usufruire di file esterni.
E' sorto il problema nel metodo di scrittura, mi da un errore che non so come risolvere.
La segnalazione è la seguente:
cannot find symbol
symbol: method store(<anonymous java.io.Writer>)
location: class java.util.Properties
di seguito vi riporto il codice della classe Properties_Write:
codice:
public class Proprerties_Write {
private Proprerties_Write() {
}
public static synchronized String getString(String pKey) {
//VALORE DI RITORNO
String myReturn=null;
Properties props = new Properties();
try {
//CARICO IL FILE DI CONFIGURAZIONE
props.load(Proprerties_Write.class.getResourceAsStream("write_info.properties"));
//LEGGO IL VALORE DI RITORNO
myReturn = props.getProperty(pKey);
}catch(IOException e) {
//ReadProprerties.showSimpleMessage("ERRORE NELLA LETTURA DEL FILE CONFIG.PRPERTIES NELLA CHIAVE: " + pKey + "\nERRORE: " + e.getMessage());
}
//RITORNA myReturn OPPURE UNA STRINGA VUOTA
return myReturn ;
}
public static synchronized void setProperty(String pKey, String pValue) throws IOException{
Properties properties = new Properties();
try {
properties.load(Proprerties_Write.class.getResourceAsStream("write_info.properties"));
properties.setProperty(pKey, pValue);
} catch (IOException ex) {
Logger.getLogger(Proprerties_Write.class.getName()).log(Level.SEVERE, null, ex);
}
properties.store (new Writer(Proprerties_Write.class.getResourceAsStream("write_info.properties")) {
@Override
public void write(char[] cbuf, int off, int len) throws IOException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void flush() throws IOException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void close() throws IOException {
throw new UnsupportedOperationException("Not supported yet.");
}
});
}
}
Ho evidenziato in rosso il codice che va in errore, di preciso viene evidenziato il metodo STORE.
Da cosa dipende? vi ripeto, la lettura funziona, l'unico problema rimasto è la scrittura.
Vi ringrazio per la diritta precedente e per ulteriori consigli.
Grazie
Luca