Java File Name Get getFileName(String localRootDirName, String ending)

Here you can find the source of getFileName(String localRootDirName, String ending)

Description

get File Name

License

Open Source License

Declaration

public static String getFileName(String localRootDirName, String ending) 

Method Source Code

//package com.java2s;
/*----------------------------------------------------------------------------- 
 * vlsSMLM Software/* ww w. j ava  2  s.c  om*/
 * 
 * Copyright (C) 2014 Matthieu Palayret
 * Department of Chemistry
 * University of Cambridge, UK
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *---------------------------------------------------------------------------*/

import java.io.File;

public class Main {
    public static String getFileName(String localRootDirName, String ending) {

        File folder = new File(localRootDirName);
        File[] listOfFiles = folder.listFiles();

        // Find the image which name contains such an Ending
        int i = 0;
        for (i = 0; i < listOfFiles.length; i++) {
            if (listOfFiles[i].getName().indexOf(ending) >= 0)
                break;
        }

        if (i == listOfFiles.length)
            return null;
        else
            return listOfFiles[i].getName();

    }
}

Related

  1. getFileName(String filepath)
  2. getFileName(String filePath)
  3. getFileName(String filePath)
  4. getFileName(String folder, final String path)
  5. getFilename(String fullFilename)
  6. getFileName(String name)
  7. getFileName(String originPath)
  8. getFilename(String path)
  9. getFileName(String path)