Snippet-56

java xml persistence (not working, reasons: unknown)

stáhnout snippet
zobrazení: SyntaxHighlighter | GeSHi | Holý text
package beans;

import java.io.Serializable;

public class Book implements Serializable {

	public Book(){
	}
	
	private String title;
	private String author;
	private int year;
	
	public void setTitle(String title) {
		this.title = title;
	}
	public void setAuthor(String author) {
		this.author = author;
	}
	public void setYear(int year) {
		this.year = year;
	}
	public String getTitle() {
		return title;
	}
	public String getAuthor() {
		return author;
	}
	public int getYear() {
		return year;
	}
}

package client;

import java.beans.XMLEncoder;
import java.io.FileOutputStream;
import java.io.IOException;
import beans.Book;

public class client {
	public static void main(String[] args) throws IOException {
		
		Book one;
		XMLEncoder e;
		FileOutputStream fos = new FileOutputStream("book.xml");
		
		e = new XMLEncoder(fos);
		one = new Book();
		one.setAuthor("Sramek");
		one.setTitle("Luciny");
		one.setYear(1998);
		e.writeObject(one);	
		fos.close();	
	}
}


Tagy:
java 56 řádků | 2008-11-29 21:47:18