Here you can find the source of encodeFilenameOmittingWhiteSpaces(String filename, String encoding)
public static String encodeFilenameOmittingWhiteSpaces(String filename, String encoding) throws Exception
//package com.java2s; //License from project: Apache License import java.net.URLEncoder; public class Main { public static String encodeFilenameOmittingWhiteSpaces(String filename, String encoding) throws Exception { if (filename == null || filename.length() == 0) return ""; else {/*from w ww. j av a2s .c o m*/ int index = filename.indexOf(' '); if (index == -1) { return encodeFilename(filename, encoding); } else { return URLEncoder.encode(filename.substring(0, index), encoding) + " " + encodeFilename(filename.substring(index + 1), encoding); } } } public static String encodeFilename(String filename, String encoding) throws Exception { String splChars = ".*[#$%?@].*"; if (filename.matches(splChars)) return URLEncoder.encode(filename, encoding); return filename; } }