Here you can find the source of isValidFileName(String fileName)
Parameter | Description |
---|---|
fileName | the File name |
public static boolean isValidFileName(String fileName)
//package com.java2s; /******************************************************************************* * <copyright> Copyright (c) 2009-2014 Bauhaus Luftfahrt e.V.. 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 </copyright> *******************************************************************************/ import java.io.File; import java.io.IOException; public class Main { /**/*w w w .j av a2 s. co m*/ * This method checks if a String represents a valid File name. * * @param fileName the File name * @return true if the File name is valid */ public static boolean isValidFileName(String fileName) { File f = new File(fileName); try { f.getCanonicalPath(); return true; } catch (IOException e) { return false; } } /** * This method checks weather a File name is valid and has a certain suffix. * * @param fileName the File name * @param suffix the File name suffix * @return true if the File name is valid and has the given suffix */ public static boolean isValidFileName(String fileName, String suffix) { if (fileName.endsWith(suffix)) { return isValidFileName(fileName); } return false; } }