Java File Name Clean cleanFileName(String name)

Here you can find the source of cleanFileName(String name)

Description

clean File Name

License

Open Source License

Declaration

public static String cleanFileName(String name) 

Method Source Code

//package com.java2s;
/**/*from  w  w w .j  a  v a 2  s .  c  o m*/
 * ?Copyright (C) 2012
 * by 52 North Initiative for Geospatial Open Source Software GmbH
 *
 * Contact: Andreas Wytzisk
 * 52 North Initiative for Geospatial Open Source Software GmbH
 * Martin-Luther-King-Weg 24
 * 48155 Muenster, Germany
 * info@52north.org
 *
 * This program is free software; you can redistribute and/or modify it under
 * the terms of the GNU General Public License serviceVersion 2 as published by the
 * Free Software Foundation.
 *
 * This program is distributed WITHOUT ANY WARRANTY; even without the implied
 * WARRANTY OF MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program (see gnu-gpl v2.txt). If not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA or
 * visit the Free Software Foundation web page, http://www.fsf.org.
 */

public class Main {
    private static final String[] ILLEGAL_FILE_NAME_CHARACTERS = new String[] { "\\", "/", ":", "*", "?", "\"", "<",
            ">", "|" };

    public static String cleanFileName(String name) {
        String cleanName = name;
        for (String s : ILLEGAL_FILE_NAME_CHARACTERS) {
            if (cleanName.contains(s))
                cleanName = cleanName.replace(s, "_");
        }
        return cleanName;
    }
}

Related

  1. cleanFileName(String badFileName)
  2. cleanFileName(String filename)
  3. cleanFilename(String filename)
  4. cleanFilename(String filename)
  5. cleanFileName(String name)
  6. cleanFileName(String path)
  7. cleanFileName(String s)
  8. cleanFileName(String sText)
  9. cleanFilename(String typeName)