Java Properties

Nick0110

Grünschnabel
Hi, habe probleme beim Einsatz von Properties.
Die Fehlermeldung lautet:
Code:
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
	at java.util.Properties.store0(Unknown Source)
	at java.util.Properties.store(Unknown Source)
	at counter.save(counter.java:46)

Der passende Code dazu lautet:

Code:
public class counter extends JFrame implements ActionListener{
	JButton open;
	Properties props;
	Properties props2;
	FileInputStream input;
	FileOutputStream output;
	int counter =  1;
	String filename;
	
	public counter(){
		JButton ink = new JButton();
		JButton get = new JButton();
		FlowLayout flow = new FlowLayout();
		
		ink.setText("erhöhen");
		get.setText("get");
		ink.addActionListener(this);
		get.addActionListener(this);
		this.setSize(300, 300);
		this.setLayout(flow);
		this.add(ink);
		this.add(get);
		filename = "counter.properties";
		
		props = new Properties();
	
	}
	
	public void save(int i){
		try{
			output = new FileOutputStream(filename);
			props.put("Counter", i);
			props.store(output, "Die Propertyliste: ");
			}catch (Exception e){
				e.printStackTrace();
			}
		
	}
	
	public int load (){
		try{
			input = new FileInputStream(filename);
			props.load(input);
			counter = Integer.parseInt(props.get("Counter").toString());
			
		}catch (Exception d){
			d.printStackTrace();
		} 
		return counter;
		
	}
	
	public void actionPerformed(ActionEvent e){
		String label = e.getActionCommand();
		
		if (label.equals("erhöhen")){
			counter++;
			try{
				if (new File(filename).exists()){
					save(counter);
				}
				else  {
					save(counter);
				}
			}catch (Exception d){
				d.printStackTrace();
			}
			
		}
		
		
		if (label.equals("get")){
			counter = load();
			System.out.println(counter);
			
		}
	}
	
	public static void main (String[] args){
		counter count = new counter();
		count.show();
	
	}
	
}

Die Fehlermeldung bezieht sich auf die Zeile
Code:
props.store(output, "Die Propertyliste: ");

Wie kommt die Fehlermeldung zustande
Danke und Grüße!
 
Zurück