setProperty

Status
Nicht offen für weitere Antworten.
T

totalhate

Gast
Hallo zusammen,

ich möchte die Eingaben die ich in meinen Programm mache in einer Datei (PKONV0002.properties) zwischenspeichern
und beim nächsten Stadt automatisch wieder laden. Die Daten die ich in meine Properties eingeben habe lädt er auch ohne Probleme, jedoch speichert er nicht meine neuen Eingaben. Fehlermeldung oder ähnliches bekomme ich auch nicht. Ich habe mal den Code der klasse geschrieben. Damit es einfacher zu lesen ist habe ich unwichtige Stellen rausgenommen und durch [... -x- ...] ersetzt.

danke schon einmal im vorraus.

Code:
package sqlkonv;

import java.util.Properties;
[... - 0 - ...]
 

public class sqlkonv
extends JFrame
implements ActionListener, CaretListener
{
	static Properties properties = null;
	
	private static final String[] mandanten = { "D", "A", "CH", "GB", "F","NL" };
	private static final String[] firmen    = { "JKG","PIV" };
	private static String hilfe; 
		
	private static int mandant;
	private static int firma;
	private static String vdat = "";
	private static String plz = "";
	private static String agrp = "";
	private static String wpnr = "";
	private static String url = "";

	private static JComboBox comfnr = new JComboBox(firmen);
	private static JComboBox comma = new JComboBox(mandanten);
	private static JTextField tfwpnr = new JTextField(3);
	private static JTextField tfplz = new JTextField(5);
	private static JTextField tfvdat = new JTextField(10);
	private static JTextField tfagrp = new JTextField(2);
	private static JButton btnhilfe = new JButton("Hilfe");
	private static JButton btnwcodes = new JButton("WCodes");
	private static JButton btnvorschau = new JButton("Vorschau");
	private static JButton btnerstellen = new JButton("Erstellen");
        private static JProgressBar pb = new JProgressBar();
    
 	private static sqlkonv wnd = new sqlkonv(); 	
 	private static Wcodes wcodes = new Wcodes();
 	private static String plaf = "javax.swing.plaf.metal.MetalLookAndFeel";
 	
 	public void letzteWerte()
 	{
 		tfwpnr.setText(properties.getProperty("WPNR",""));
 		tfvdat.setText(properties.getProperty("Versanddatum",""));
 		tfagrp.setText(properties.getProperty("Ausgabegruppe",""));
 		comfnr.setSelectedItem(properties.getProperty("Firma",""));
 		comma.setSelectedItem(properties.getProperty("Mandant",""));
 		tfplz.setText(properties.getProperty("PLZ",""));
 		this.caretUpdate(null);
 	}
 	
 	public void speicherWerte()
 	{
 		properties.setProperty("Firma", comfnr.getSelectedItem()+"");
 		properties.setProperty("Mandant", comma.getSelectedItem()+"");
 		properties.setProperty("Versanddatum", vdat);
 		properties.setProperty("WPNR", wpnr);
 		properties.setProperty("Ausgabegruppe", agrp);
 		properties.setProperty("PLZ",plz);
 	}
 	
	public sqlkonv()
	{		
		super("Automatisierte SQL-Datenkonvertierung");
		
		JOptionPane.showMessageDialog(wnd,"Version 0.1","Version 0.1",1);
		
                [... - 1 - ...]
		
		try
		{
			properties = new Properties();
			properties.load(new FileInputStream("./PKONV0002.properties"));
			hilfe = properties.getProperty("Hilfe");
			url = (properties.getProperty("connectionUrl"));
		}
		catch(Exception Ex)
		{
			JOptionPane.showMessageDialog(wnd,Ex.getLocalizedMessage(),"dbhandler -1-",1);
			System.out.println(Ex.getLocalizedMessage());
			pb.setString("Zugriff auf Konfigurationsdatei nicht möglich");
			hilfe = "Zugriff auf Konfigurations-\ndatei nicht möglich";
		}
		this.letzteWerte();
	}
	
	private JMenu createFileMenu()
	{
             [... - 2 - ...]
	}
	
	public void caretUpdate(CaretEvent event)
	{
 		agrp = tfagrp.getText();
 		wpnr = tfwpnr.getText();
		vdat = tfvdat.getText();
		plz  = tfplz.getText();
 		pb.setString("");
 		this.speicherWerte();
	}

	public String geturl()
        [... - 3a - ...]
	public int getmandant()
        [... - 3b - ...]
	public int getfirma()
        [... - 3c - ...]
	public String getplz()
        [... - 3d - ...]
	
	public void actionPerformed(ActionEvent event) 
	{	
		pb.setString("");
		mandant = comma.getSelectedIndex();
		mandant++;
		firma = comfnr.getSelectedIndex();
		firma++;
		tfplz.setEditable(true);
		if (mandant != 1)
		{
			comfnr.setSelectedIndex(1);
			firma = 2;
			tfplz.setEditable(false);
		}
		
		String cmd = event.getActionCommand();

		[... - 4 - ...]
	}
	
	public static void main(String[] args)
	{
                [... - 5 - ...]
	}
}
 

outbreaker

Bekanntes Mitglied
hier läds du aus einer Datei deine Properties
Code:
properties.load(new FileInputStream("./PKONV0002.properties"));

aber wo schreibst du das was in dem properties Objekt steht wieder zurück in die Datei?

übersehe ich das oder machst du das nicht?

Hier setzt du nur die Werte im Objekt aber nicht in der Datei meiner Meinung nach:

Code:
public void speicherWerte()
   {
      properties.setProperty("Firma", comfnr.getSelectedItem()+"");
      properties.setProperty("Mandant", comma.getSelectedItem()+"");
      properties.setProperty("Versanddatum", vdat);
      properties.setProperty("WPNR", wpnr);
      properties.setProperty("Ausgabegruppe", agrp);
      properties.setProperty("PLZ",plz);
   }
 
T

totalhate

Gast
mh, dann ist die Frage wohl wie schreibe ich das was in properties steht zurück in die Datei.

Ich habe den Befehl store(...) ausprobiert ( so wie er auf der Seite stand: http://www.galileocomputing.de/open...12_009.htm#mj4fd19fd3d33da2336fc5c9337c38a10d). Da bekomme ich jedoch eine Fehlermeldung:


java.lang.Error: Unresolved compilation problem:
The method store(OutputStream, String) in the type Properties is not applicable for the arguments (Writer, null)

at sqlkonv.sqlkonv.speicherWerte(sqlkonv.java:79)
at sqlkonv.sqlkonv.caretUpdate(sqlkonv.java:228)
at sqlkonv.sqlkonv.letzteWerte(sqlkonv.java:64)
at sqlkonv.sqlkonv.<init>(sqlkonv.java:189)
at sqlkonv.sqlkonv.<clinit>(sqlkonv.java:52)
Exception in thread "main"
Code:
        private Writer writer = null;

 	public void speicherWerte()
 	{
 		properties.setProperty("Firma", comfnr.getSelectedItem()+"");
 		properties.setProperty("Mandant", comma.getSelectedItem()+"");
 		properties.setProperty("Versanddatum", vdat);
 		properties.setProperty("WPNR", wpnr);
 		properties.setProperty("Ausgabegruppe", agrp);
 		properties.setProperty("PLZ",plz);
 		try {
 			writer = new FileWriter("PKONV0002.properties" );
			properties.store(writer, null);
		} catch (IOException e) {
			e.printStackTrace();
		}
 	}
 

outbreaker

Bekanntes Mitglied
nimm mal nicht null sondern einen leeren String

Code:
properties.store(writer, "");
 
T

totalhate

Gast
java.lang.Error: Unresolved compilation problem:
The method store(OutputStream, String) in the type Properties is not applicable for the arguments (Writer, String)

at sqlkonv.sqlkonv.speicherWerte(sqlkonv.java:79)
at sqlkonv.sqlkonv.caretUpdate(sqlkonv.java:228)
at sqlkonv.sqlkonv.letzteWerte(sqlkonv.java:64)
at sqlkonv.sqlkonv.<init>(sqlkonv.java:189)
at sqlkonv.sqlkonv.<clinit>(sqlkonv.java:52)
Exception in thread "main"

den Writer will er aber auch nicht ...
 

outbreaker

Bekanntes Mitglied
aso ich habe nicht richtig gelesen was die Exception ist nimm mal einen OutputStream und keinen Writer

versuch mal FileOutputStream
 
T

totalhate

Gast
hatte irgendnen komischen outputStream probiert, der aber auch nen Fehler gebracht hat. der FileOutputStream funktioniert, danke...
 
Status
Nicht offen für weitere Antworten.

Ähnliche Java Themen

Neue Themen


Oben