Here you can find the source of getFilenameParts(File file)
Parameter | Description |
---|---|
file | a parameter |
public static String[] getFilenameParts(File file)
//package com.java2s; /******************************************************************************* * Copyright (c) 2010-2015 BSI Business Systems Integration AG. * 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:/*w w w .j ava2s . c o m*/ * BSI Business Systems Integration AG - initial API and implementation ******************************************************************************/ import java.io.File; public class Main { /** * @param file * @return an array with two elements, [0] contains the file-name without extension [1] contains the file-extension */ public static String[] getFilenameParts(File file) { if (file == null) { return null; } return getFilenameParts(file.getName()); } /** * @param fileName * @return an array with two elements, [0] contains the file-name without extension [1] contains the file-extension */ public static String[] getFilenameParts(String fileName) { if (fileName == null) { return null; } int index = fileName.lastIndexOf('.'); if (index < 0) { return new String[] { fileName, null }; } else { return new String[] { fileName.substring(0, index), fileName.substring(index + 1) }; } } }