English 中文(简体)
如何使用档案
原标题:how to do Serializtionf of a file
  • 时间:2009-12-19 12:03:29
  •  标签:
  • java

i 拥有被称作违约xml的Xml文档,样本内容为

<check>hi</check>

in my application i am doing an operation such that it wil operate on the xml and writes the new value to it, by overriding the newvalue on the oldone ex:

<check>hi updated</check>

我现在宣布我的申请结束。

我的问题是:

每当一开始申请时,就应当把违约xml的内容作为证据。

<check>hi<check> 

而不是

<check>hi updated</check>

如何实现这一点,可以证明我已采取步骤执行这一节点任何样本守则,以落实这一条。

i wil b 感谢贵重答复

问题回答

Um...don t overwrite the file when? 保存记忆的变化或临时复印件。

书写数据:

FileOutputStream os = new FileOutputStream("C:/cust.xml");
XMLEncoder encoder = new XMLEncoder(os);
Person p = new Person();
p.setFirstName("John");
encoder.writeObject(p);
encoder.close(); 

阅读数据:

FileInputStream os = new FileInputStream("C:/cust.xml");
XMLDecoder decoder = new XMLDecoder(os);
Person p = (Person)decoder.readObject();
decoder.close();

EDIT: You can also use XStream Library. Here, 您将找到一份完整的论文。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签