Java File Name Get getFileNameOnly(String fileName)

Here you can find the source of getFileNameOnly(String fileName)

Description

get File Name Only

License

Apache License

Declaration

public static String getFileNameOnly(String fileName) 

Method Source Code


//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

import java.io.*;

public class Main {
    public static String getFileNameOnly(String fileName) {
        int index = -1;
        String auxString = fileName, returnedValue = null;

        index = fileName.lastIndexOf(File.separator);

        if (index == -1)
            index = fileName.lastIndexOf('/');

        if (index != -1)
            auxString = fileName.substring(index + 1);

        // Remove extension
        index = auxString.lastIndexOf('.');
        if (index != -1)
            auxString = auxString.substring(0, index);

        returnedValue = auxString;//  w  w w  .  j  a va 2 s. com

        return returnedValue;
    }
}

Related

  1. getFileNameList(String path)
  2. getFileNameNoSuffix(String fullName)
  3. getFileNameNoSuffix(String path)
  4. getFileNameOfPath(final String filePath)
  5. getFilenameOnly(File file)
  6. getFileNameOnlyFromFileObject(File fileToProcess)
  7. getFileNamePart(final File file)
  8. getFilenameParts(File file)
  9. getFileNames(byte[] zipFile)