вторник, 22 януари 2008 г.

Търся в Гуугъл: XMLEncoder -> http://www.java2s.com/Code/Java/Swing-JFC/TheMyBeanJavaBeanComponent.htm

The MyBean JavaBean Component

import java.awt.Point;import java.beans.XMLEncoder;
import java.io.BufferedOutputStream;import java.io.FileOutputStream;
import java.io.IOException;
public class MyBean
private String names[];
private Point p;
private int length;
public String[] getNames() { return names; }
public Point getPoint() { return p; }
public int getLength() { return length; }
public void setNames(String newValue[]) { names = newValue; }
public void setPoint(Point newValue) { p = newValue; }
public void setLength(int newValue) { length = newValue; }
public static void main(String args[]) throws IOException
// Create MyBean
MyBean saveme = new MyBean();
saveme.setNames(new String[] { "one", "two", "three" });
saveme.setPoint(new Point(15, 27));
// Save
XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream( new FileOutputStream("C:\\saveme.xml")));
encoder.writeObject(saveme); encoder.close();

понеделник, 21 януари 2008 г.

Application properties

Записване на настройки на приложение перманентно:

- properties file

- java.beans.XMLEncoder
java.beans.XMLEncoder and java.beans.XMLDecoder. Will serialize a vector straight off without you having to write any code IF theobjects in the vector have:1. A default public constructor2. public accessor methods for the object properties you want toserialize OR the properties are publicNo need to parse anything or load up an XML parser. It works much likeObjectInputStream and ObjectOutputStream, except what you get is XML.

- java.io.Serializable
- Java Persistence API