Here you can find the source of saveSorted(Properties props, File file)
Parameter | Description |
---|---|
props | Properties |
file | file |
Parameter | Description |
---|---|
Exception | an exception |
public static void saveSorted(Properties props, File file) throws Exception
//package com.java2s; //License from project: Apache License import java.io.*; import java.util.*; public class Main { /**//w w w. j ava 2s .c o m * * Sort and save properties to a file. * * @param props Properties * @param file file * @throws Exception */ public static void saveSorted(Properties props, File file) throws Exception { try (FileOutputStream fout = new FileOutputStream(file)) { Properties sorted = new Properties() { @Override public Set<Object> keySet() { return Collections.unmodifiableSet(new TreeSet<Object>(super.keySet())); } @Override public synchronized Enumeration<Object> keys() { return Collections.enumeration(new TreeSet<Object>(super.keySet())); } @Override public Set<String> stringPropertyNames() { return Collections.unmodifiableSet(new TreeSet<String>(super.stringPropertyNames())); } }; sorted.putAll(props); sorted.storeToXML(fout, null); fout.flush(); } } }