Here you can find the source of isFilenameValid(String file)
Parameter | Description |
---|---|
file | the name of a file |
public static boolean isFilenameValid(String file)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.IOException; public class Main { /**/*from www . j ava2 s .com*/ * Only check if a given filename is valid according to the OS rules. * * You still need to handle other failures when actually creating * the file (e.g. insufficient permissions, lack of drive space, security restrictions). * @param file the name of a file * @return true if the file is valid, false otherwise */ public static boolean isFilenameValid(String file) { File f = new File(file); try { f.getCanonicalPath(); return true; } catch (IOException e) { return false; } } }