Java Path Create nio createProperties(final Path directory, final Properties properties)

Here you can find the source of createProperties(final Path directory, final Properties properties)

Description

create Properties

License

Apache License

Declaration

static Path createProperties(final Path directory, final Properties properties)
            throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException,
            InvocationTargetException, IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import java.nio.file.Files;
import java.nio.file.Path;

import java.util.Objects;
import java.util.Properties;

public class Main {
    static Path createProperties(final Path directory, final Properties properties)
            throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException,
            InvocationTargetException, IOException {
        Objects.requireNonNull(directory, "directory");
        Objects.requireNonNull(properties, "properties");
        if (!Files.isDirectory(directory)) {
            throw new IllegalArgumentException("directory " + directory + " must be a directory");
        }/*from w w  w  .j a  v a2  s .c  om*/
        Path configurationFile = directory.resolve(getConfigurationFileName());
        properties.store(Files.newOutputStream(configurationFile), "configuration");
        return configurationFile;
    }

    private static String getConfigurationFileName() throws ClassNotFoundException, NoSuchMethodException,
            IllegalAccessException, IllegalArgumentException, InvocationTargetException {
        Class<?> clazz = Class.forName("com.cardshifter.core.modloader.ModLoaderHelper");
        Method method = clazz.getDeclaredMethod("getConfigurationFileName");
        method.setAccessible(true);
        return (String) method.invoke(null);
    }
}

Related

  1. createPath(String fileName, String subfolder)
  2. createPathComparator()
  3. createPathMatcher(String[] patterns)
  4. createPathOrNull(String pathString)
  5. createPathRelativizer(Path path, boolean doRelativize)
  6. createRandomClass(String className, Path dir)
  7. createRandomFolder(Path basePath)
  8. createRandomFolders(Path basePath, int numberOfFolders)
  9. createRelativePath(File baseDirFile, File file)