Java File Name Get getFileNameList(String path)

Here you can find the source of getFileNameList(String path)

Description

get File Name List

License

Open Source License

Declaration

public static ArrayList<String> getFileNameList(String path) 

Method Source Code

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

import java.io.File;

import java.util.ArrayList;
import java.util.Collections;

public class Main {

    public static ArrayList<String> getFileNameList(String path) {
        File file = new File(path);
        File[] tempList = file.listFiles();
        ArrayList<Integer> tnames = new ArrayList<Integer>();
        ArrayList<String> names = new ArrayList<String>();
        for (int i = 0; i < tempList.length; i++) {
            if (tempList[i].isFile()) {
                tnames.add(Integer.valueOf(tempList[i].getName()));
            }//ww  w.j a  v a 2s. com
        }
        Collections.sort(tnames);
        for (int i = 0; i < tnames.size(); i++) {
            names.add(tnames.get(i) + "");
        }
        if (names.size() == 0)
            names.add("-1");
        return names;
    }
}

Related

  1. getFileNameFromFullPath(String fullPath)
  2. getFileNameFromZipEntry(ZipEntry entry)
  3. getFileNameInJCCTrayHome(String fileName)
  4. getFileNameList(File[] files)
  5. getFileNameList(String dir)
  6. getFileNameNoSuffix(String fullName)
  7. getFileNameNoSuffix(String path)
  8. getFileNameOfPath(final String filePath)
  9. getFilenameOnly(File file)