此方法对URL进行编码,从URL中删除空格,并将其替换为“%20”。
/** * 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. */ //package com.nowjava; /** from 时 代 J a v a 公 众 号**/ public class Main { /** * This method encodes the URL, removes the spaces from the URL and replaces the same with <code>"%20"</code>. * This method is required to fix Bug 77840. * * @param input * @return String * @since 3.0.2 */ public static String urlEncodeForSpaces(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");