Here you can find the source of isValidPath(String path)
Parameter | Description |
---|---|
path | Path to validate. |
public static boolean isValidPath(String path)
//package com.java2s; /****************************************************************************** * Copyright (c) Child-In-Time 2016. All rights reserved. * * * * @author Tim Visee * * @author Nathan Bakhuijzen * * @author Timo van den Boom * * @author Jos van Gent * * * * Open Source != No Copyright * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the "Software") * * to deal in the Software without restriction, including without limitation * * the rights to use, copy, modify, merge, publish, distribute, sublicense, * * and/or sell copies of the Software, and to permit persons to whom the * * Software is furnished to do so, subject to the following conditions: * * * * The above copyright notice and this permission notice shall be included * * in all copies or substantial portions of the Software. * * * * You should have received a copy of The MIT License (MIT) along with this * * program. If not, see <http://opensource.org/licenses/MIT/>. * ******************************************************************************/ import java.nio.file.Paths; public class Main { /**/*from w ww.j av a 2s . co m*/ * Check whether a path is valid and parsable, without the file needing to exist. * * @param path Path to validate. * * @return True if the path is valid, false if not. */ public static boolean isValidPath(String path) { // Validate the path try { // Try to parse the given path as string representation into a path instance Paths.get(path); // The path seems to be valid return true; } catch (Exception ignored) { } // The path seems to be invalid, return false return false; } }