Java FileWriter Write saveFile(String path, Map> setup)

Here you can find the source of saveFile(String path, Map> setup)

Description

Save file of settings when given the correct format of settings.

License

Open Source License

Parameter

Parameter Description
path the path to save to including filename.
setup the setup of the settings.

Exception

Parameter Description
IOException Signals that an I/O exception has occurred.

Declaration

public static void saveFile(String path, Map<String, Map<String, String>> setup) throws IOException 

Method Source Code

//package com.java2s;
/*/* www  . ja va 2  s  . com*/
 * Copyright (c) 2015 Zachary Rauen
 * Website: www.ZackRauen.com
 *
 * All rights reserved. Use is subject to license terms.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * If a copy of the License is not provided with the work, you may
 * obtain a copy 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.FileWriter;
import java.io.IOException;

import java.io.PrintWriter;

import java.util.Map;

public class Main {
    /**
     * Save file of settings when given the correct format of settings.
     *
     * @param path the path to save to including filename.
     * @param setup the setup of the settings.
     * @throws IOException Signals that an I/O exception has occurred.
     */
    public static void saveFile(String path, Map<String, Map<String, String>> setup) throws IOException {
        PrintWriter p = new PrintWriter(new FileWriter(path), true);
        for (String heading : setup.keySet()) {
            p.println("[" + heading + "]");
            for (String key : setup.get(heading).keySet()) {
                p.println(key + "=" + setup.get(heading).get(key));
            }
            p.println("");
        }
        p.close();
    }
}

Related

  1. saveFile(File file, String fileContent)
  2. saveFile(File file, String text, boolean append)
  3. saveFile(List contents, String fileName)
  4. saveFile(String filePath, String content)
  5. saveFile(String filePath, String data)
  6. saveFile(String path, String content)
  7. SaveFile(String path, String data, boolean deleteOnExit)
  8. saveFile(String path, String sb)
  9. saveFile(String[] lines, String savedName, String extension)