Java ClassLoader saveProperties(Properties properties, String name)

Here you can find the source of saveProperties(Properties properties, String name)

Description

save Properties

License

Open Source License

Declaration

public static void saveProperties(Properties properties, String name) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.File;

import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.net.URLDecoder;
import java.util.Properties;

public class Main {
    public static void saveProperties(Properties properties, String name) {
        try {/*from   w  w w .j  a va  2 s.  co  m*/
            // Use -Drepox.data.dir= in the VM parameters in order to pass an already existing configuration.properties and gui.properties
            String configsDataDir = System.getProperty("repox.data.dir");
            String configurationFile;
            if (configDataDirAlreadyExists(configsDataDir, name))
                configurationFile = URLDecoder.decode(configsDataDir + File.separator + name, "ISO-8859-1");
            else {
                URL configurationURL = Thread.currentThread().getContextClassLoader().getResource(name);
                configurationFile = URLDecoder.decode(configurationURL.getFile(), "ISO-8859-1");
            }
            properties.store(new FileOutputStream(configurationFile), null);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static boolean configDataDirAlreadyExists(String configsDataDir, String configurationFilename) {
        if (configsDataDir == null || configsDataDir.isEmpty())
            return false;

        File configFile = new File(configsDataDir + File.separator + configurationFilename);
        if (!configFile.exists()) {
            System.out.println("Load Config files from Java Variables -- " + configurationFilename
                    + " file doesn't exist on the specified directory");
            return false;
        }

        return true;
    }
}

Related

  1. loadXml()
  2. locateFile(String name)
  3. read(String fileName)
  4. readFromFile(Object obj, String fileName)
  5. readSampleJson(String name)
  6. scanPackage(String path)
  7. searchByAttributeKey(String key)
  8. storePropertiesFile(String fileName, String filePath, String storeComment)
  9. toTypeArray(String[] s)