Java File Name Extract extractFileNameFromBAMLocation(String location)

Here you can find the source of extractFileNameFromBAMLocation(String location)

Description

Converts strings like /data/results/DNA1234049.bam or DNA1234049.bam to DNA1234049

License

Open Source License

Parameter

Parameter Description
location file path to bam file. String should end in .bam (case insensitive)

Declaration

public static String extractFileNameFromBAMLocation(String location) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/* w  w w .  ja v a 2  s.c  o m*/
     * Converts strings like /data/results/DNA1234049.bam or DNA1234049.bam
     * to DNA1234049
     * @param location file path to bam file. String should end in .bam (case insensitive)
     * @return
     */
    public static String extractFileNameFromBAMLocation(String location) {

        String fileName = "";
        location = location.toLowerCase();
        String[] split = location.split("/");

        for (String s : split) {
            if (s.endsWith(".bam")) {
                fileName = s.replaceAll(".bam$", "");
            }
        }

        return fileName;
    }
}

Related

  1. extractFileName(String path)
  2. extractFilename(String path)
  3. extractFileName(String path)
  4. extractFilename(String path)
  5. extractFileName(String url)
  6. extractFileNameFromContentDisposition(String contentDisposition)
  7. extractFileNameFromPath(final String filePath, char separatorChar)
  8. extractFileNameFromPath(final String path)
  9. extractFilenameFromPath(String path)