Java Path Create nio createPathOrNull(String pathString)

Here you can find the source of createPathOrNull(String pathString)

Description

create Path Or Null

License

Open Source License

Return

a valid path, or null if a valid path could not be created from given pathString.

Declaration

public static Path createPathOrNull(String pathString) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014 Bruno Medeiros and other Contributors.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*  w ww .  ja  va 2  s . co m*/
 *     Bruno Medeiros - initial API and implementation
 *******************************************************************************/

import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;

public class Main {
    /** @return a valid path, 
     * or null if a valid path could not be created from given pathString. */
    public static Path createPathOrNull(String pathString) {
        try {
            return Paths.get(pathString);
        } catch (InvalidPathException ipe) {
            return null;
        }
    }
}

Related

  1. createMainClassAndBuildFileWithDeps(String targetName, String deps, Path dir)
  2. createOverwriteDirectory(Path path)
  3. createPath(String fileName, String subfolder)
  4. createPathComparator()
  5. createPathMatcher(String[] patterns)
  6. createPathRelativizer(Path path, boolean doRelativize)
  7. createProperties(final Path directory, final Properties properties)
  8. createRandomClass(String className, Path dir)
  9. createRandomFolder(Path basePath)