Java Class Path getClassNameByFile(String filePath, List className, boolean childPackage)

Here you can find the source of getClassNameByFile(String filePath, List className, boolean childPackage)

Description

get Class Name By File

License

LGPL

Declaration

private static List<String> getClassNameByFile(String filePath, List<String> className, boolean childPackage)
        throws UnsupportedEncodingException 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.io.File;
import java.io.UnsupportedEncodingException;

import java.net.URLDecoder;
import java.util.ArrayList;

import java.util.List;

public class Main {

    private static List<String> getClassNameByFile(String filePath, List<String> className, boolean childPackage)
            throws UnsupportedEncodingException {
        List<String> myClassName = new ArrayList<String>();
        filePath = URLDecoder.decode(filePath, "utf-8");
        File file = new File(filePath);
        File[] childFiles = file.listFiles();
        for (File childFile : childFiles) {
            if (childFile.isDirectory()) {
                if (childPackage) {
                    myClassName.addAll(getClassNameByFile(childFile.getPath(), myClassName, childPackage));
                }/* w w w  .  ja v  a 2  s . c  om*/
            } else {
                String childFilePath = childFile.getPath();
                if (childFilePath.endsWith(".class")) {
                    childFilePath = childFilePath.substring(childFilePath.indexOf("\\classes") + 9,
                            childFilePath.lastIndexOf("."));
                    childFilePath = childFilePath.replace("\\", ".");
                    myClassName.add(childFilePath);
                }
            }
        }

        return myClassName;
    }
}

Related

  1. getClassFilePath(Class clazz)
  2. getClassFilePath(Class clazz)
  3. getClassFilePath(Class clazz)
  4. getClassFilePath(final Class cls)
  5. getClassFilePath(String package_name, String class_name)
  6. getDirectoryPath(Class owner)
  7. getFile(Class base, String path)
  8. getFullPathOfClass(Class cls)
  9. getFullpathRessources(Class c, String ressource)