write Properties File - Android java.util

Android examples for java.util:Properties

Description

write Properties File

Demo Code


//package com.java2s;

import java.io.FileOutputStream;
import java.io.IOException;

import java.io.OutputStream;

import java.util.Properties;

public class Main {
    public static void writePropertiesFile(String filename) {
        Properties properties = new Properties();
        try {/*ww  w.  jav  a  2  s.  c  o m*/
            OutputStream outputStream = new FileOutputStream(filename);
            properties.setProperty("username", "myname");
            properties.setProperty("password", "mypassword");
            properties.setProperty("chinese", "asdf");
            properties.store(outputStream, "author: pengyixing@sina.com");
            outputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Related Tutorials