Here you can find the source of toFilename(String name, String extension)
public static String toFilename(String name, String extension)
//package com.java2s; /******************************************************************************* * Copyright (c) 2008, 2010 SAP AG.//from w w w.jav a 2 s. co m * 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: * SAP AG - initial API and implementation *******************************************************************************/ public class Main { public static String toFilename(String name, String extension) { return toFilename(name, "", extension); //$NON-NLS-1$ } /** * Build a file name. * Convert non-letters or digits to underscore. * @param prefix the prefix of the file * @param suffix the suffix * @param extension the file extension * @return the combined file name */ public static String toFilename(String prefix, String suffix, String extension) { StringBuilder buf = new StringBuilder(prefix.length() + suffix.length() + extension.length() + 1); for (String s : new String[] { prefix, suffix }) { for (int ii = 0; ii < s.length() && ii < 20; ii++) { char c = s.charAt(ii); if (Character.isLetterOrDigit(c)) buf.append(c); else buf.append("_"); //$NON-NLS-1$ } } buf.append(".").append(extension); //$NON-NLS-1$ return buf.toString(); } }