Java String Escape escapeToFileName(String name)

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

Description

Create escaped filename from a string

License

Open Source License

Parameter

Parameter Description
name any string

Return

file compatible string

Declaration

public static String escapeToFileName(String name) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.
 * 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:/* ww  w  .  java 2 s.c  om*/
 *     VTT Technical Research Centre of Finland - initial API and implementation
 *******************************************************************************/

import java.io.UnsupportedEncodingException;

public class Main {
    /**
     * Create escaped filename from a string
     * 
     * @param name any string
     * @return file compatible string
     */
    public static String escapeToFileName(String name) {
        try {
            return java.net.URLEncoder.encode(name, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            // never expected
            throw new RuntimeException(e);
        }
    }
}

Related

  1. escapeRegexp(final String str)
  2. escapeRegexpSymbol(String expr)
  3. escapeReservedWord(String input)
  4. escapeSelected(String str, String chars)
  5. escapeSolr(String value)
  6. escapeUnicode(String s)
  7. escapeUnicodeString(final String input, final boolean escapeAscii)
  8. escapeUnsafeCharacters(String anyURI, boolean escapePercent)
  9. escapeWiki(String s)