Here you can find the source of writeFile(String path, Properties store, String comment)
Parameter | Description |
---|---|
path | Path to the file. |
store | Contains the data. |
comment | Comment that should be written in the file. May be null. |
Parameter | Description |
---|---|
IOException | If the method failes to save the properties, an IOException will be thrown. |
NullPointerException | If path or store are null, a NullPointerException will be thrown. |
public static void writeFile(String path, Properties store, String comment) throws IOException
//package com.java2s; /*//w w w .j a v a2 s .c om * Copyright 2007-2009 Alexander Fabisch * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.*; import java.util.Properties; public class Main { /** * Writes data of a Properties object to a properties file. If necessary, new directories will be created. * * @param path * Path to the file. * @param store * Contains the data. * @param comment * Comment that should be written in the file. May be null. * @throws IOException * If the method failes to save the properties, an IOException will be thrown. * @throws NullPointerException * If path or store are null, a NullPointerException will be thrown. */ public static void writeFile(String path, Properties store, String comment) throws IOException { checkNullReference(path, store); File file = new File(path); File topDir = file.getParentFile(); if (topDir != null && !topDir.exists()) { topDir.mkdirs(); } FileOutputStream fos = new FileOutputStream(file); store.store(fos, comment); } private static void checkNullReference(Object... objects) { for (Object o : objects) { if (o == null) { throw new NullPointerException("objects must not be null"); } } } }