集册 Java实例教程 此方法对URL进行编码,从URL中删除空格和方括号,并将其替换为“%20”、“5B”、“5D”和“%7B”、“7D”。

此方法对URL进行编码,从URL中删除空格和方括号,并将其替换为“%20”、“5B”、“5D”和“%7B”、“7D”。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

1290
此方法对URL进行编码,从URL中删除空格和方括号,并将其替换为“%20”和“%5B”,“%5D”和“%7B”,“%7D”。

/**

 * Copyright (c) 2005-2006 Aptana, Inc.

 *

 * 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. If redistributing this code,

 * this entire header must remain intact.

 */
 /* from 
 时代Java公众号*/

//package com.nowjava;


public class Main {

    /**

     * This method encodes the URL, removes the spaces and brackets from the URL and replaces the same with

     * <code>"%20"</code> and <code>"%5B" and "%5D"</code> and <code>"%7B" "%7D"</code>.

     * 

     * @param input

     * @return String

     * @since 3.0.2

     */

    public static String urlEncodeFilename(char[] input) {


        if (input == null) {

            return null;

        }


        StringBuffer retu = new StringBuffer(input.length);

        for (int i = 0; i < input.length; i++) {

            if (input[i] == ' ') {

                retu.append("%20"); //$NON-NLS-1$

            } else if (input[i] == '[') {

                retu.append("%5B"); //$NON-NLS-1$

            } else if (input[i] == ']') {
            /*来自 
             n o w  j a v a  . c o m*/

                retu.append("%5D"); //$NON-NLS-1$

            } else if (input[i] == '{') {

                retu.append("%7B"); //$NON-NLS-1$

            } else if (input[i] == '}') {

                retu.append("%7D"); //$NON-NLS-1$

            } else if (input[i] == '`') {

                retu.ap
展开阅读全文