Create a xml file named Test.xml in source folder.
And using the pasted code we can write in to any xml file..
Many options are available for generating XML documents. XmlWriter is by no means the best tool for every XML creation task, but it can fill the gap that exists between approaches that are too simple, too heavy, and too complex.
Here we used XMLEncoder class.
using the BufferedOutputStream we can write to the xml file:)
Here we have a small example which can easily understandable::::
/**
* @(#)DemoApp.java
*
* DemoApp application
*
* @Sujay
* @version 1.00 2011/7/25
*/
import java.beans.XMLEncoder;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
public class DemoApp extends javax.swing.JFrame{
public static void main(String[] args)throws FileNotFoundException
{
try {
// TODO, add your application code
XMLEncoder e = new XMLEncoder(new BufferedOutputStream(new FileOutputStream("Test.xml")));
e.writeObject("Hello, world");
System.out.print("Hello");
e.close();
} catch(FileNotFoundException ex) {
System.out.print("Error :"+ex);
}
}
}
Comments
Post a Comment