Java tutorial
//package com.java2s; /* * File: $RCSfile$ * * Copyright (c) 2005 Wincor Nixdorf International GmbH, * Heinz-Nixdorf-Ring 1, 33106 Paderborn, Germany * All Rights Reserved. * * This software is the confidential and proprietary information * of Wincor Nixdorf ("Confidential Information"). You shall not * disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered * into with Wincor Nixdorf. */ import java.util.Iterator; import java.util.Set; import java.util.Properties; import java.util.TreeSet; import java.io.UnsupportedEncodingException; public class Main { /** * Return serializable data, the format of these data is placed like the following format * ${key}=${value} * * @param properties Properties instance * @return serializable data * @throws java.io.UnsupportedEncodingException * if errors occure during text converted to UTF-8 encoding */ public static byte[] getSerializablePropertiesData(Properties properties) throws UnsupportedEncodingException { Set keySet = properties.keySet(); TreeSet keys = new TreeSet(keySet); Iterator it = keys.iterator(); StringBuffer bf = new StringBuffer(); while (it.hasNext()) { String item = (String) it.next(); String resourceValue = (String) properties.get(item); bf.append(item); bf.append("="); bf.append(resourceValue); bf.append("\n"); } return bf.toString().getBytes("UTF-8"); } }