- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Export Preferences to XML file in Java
In order to export preferences to an XML file in Java, we need to use the exportSubtree() method. This method emits an XML document showing all of the preferences contained in this node and all of its descendants. This XML document provides an offline backup of the subtree rooted at the node.
Declaration − The java.util.prefs.Preferences.exportSubtree method is declared as follows −
public abstract void exportSubtree(OutputStream os) throws IOException, BackingStoreException
Let us see a program to export preferences to an XML file in Java −
import java.io.FileOutputStream; import java.util.prefs.Preferences; public class Example { public static void main(String args[]) throws Exception { Preferences pre = Preferences.userRoot(); Preferences prefs = pre.node("Example"); myPrefs.put("S", "s"); myPrefs.put("A", "a"); myPrefs.put("D", "d"); FileOutputStream fos = new FileOutputStream("abc.xml"); prefs.exportSubtree(fos); fos.close(); } }
The command window looks as follows −
An XML file is created in the bin −
- Related Articles
- How to echo XML file in PHP
- How to read the XML file in PowerShell?
- How to Export and import CSV file manually in PowerShell?
- How to convert XML file into array in PHP?
- Transforming XML file into fixed length flat file in SAP
- How to get specific nodes in xml file in Python?
- Export specified field of a collection in mongodb / mongodump to file?
- What is a TestNG xml file in TestNG?
- What is the use of the "export" clause in a module-info file in Java 9?
- How to export the binary file of a code in Arduino IDE
- How to create animation using XML file in an Android App?
- System measurement of SAP HANA system in XML file
- Write a Python program to export a dataframe to an html file
- How to create Python objects based on an XML file?
- How to add an attribute to the XML file using Powershell?

Advertisements