Java File Name Get getFilenameParts(File file)

Here you can find the source of getFilenameParts(File file)

Description

get Filename Parts

License

Open Source License

Parameter

Parameter Description
file a parameter

Return

an array with two elements, [0] contains the file-name without extension [1] contains the file-extension

Declaration

public static String[] getFilenameParts(File file) 

Method Source Code

//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) };
        }
    }
}

Related

  1. getFileNameOfPath(final String filePath)
  2. getFilenameOnly(File file)
  3. getFileNameOnly(String fileName)
  4. getFileNameOnlyFromFileObject(File fileToProcess)
  5. getFileNamePart(final File file)
  6. getFileNames(byte[] zipFile)
  7. getFileNames(File path, Vector result)
  8. getFileNames(File zipFile, Pattern pattern)
  9. getFileNames(File[] files)