Example usage for java.io File getName

List of usage examples for java.io File getName

Introduction

In this page you can find the example usage for java.io File getName.

Prototype

public String getName() 

Source Link

Document

Returns the name of the file or directory denoted by this abstract pathname.

Usage

From source file:Main.java

public static void init(Context context) {
    voice_wechat_paths = new ArrayList<>();
    voice_qq_paths = new ArrayList<>();

    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        File dir = Environment.getExternalStorageDirectory();
        File f = new File(dir + "/tencent/MicroMsg");

        if (f.exists() && f.canRead() && f.isDirectory()) {
            File[] files = f.listFiles();
            if (files == null || files.length == 0) {
                return;
            }// www. j  a v  a  2 s . c  o  m

            for (File f0 : files) {
                if (f0.isDirectory() && f0.getName().length() > 24) {
                    voice_wechat_paths.add(f0.getAbsolutePath() + "/voice2");
                }
            }
        }

        File exportDir = new File(dir, "silkv3_mp3");
        if (!exportDir.exists()) {
            exportDir.mkdirs();
        }

        export_dir = exportDir.getAbsolutePath();
    }
}

From source file:Main.java

public static boolean confirmOverwrite(Component comp, File file) {
    if (file.exists()) {
        int decision = JOptionPane.showConfirmDialog(comp, file.getName() + " exists. Overwrite?",
                "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
        if (decision == JOptionPane.NO_OPTION) {
            return false;
        }/*from   w ww  .j a  v  a 2s.c o  m*/
    }
    return true;
}

From source file:onl.area51.httpd.util.ContentTypeResolver.java

public static ContentType resolve(File f) {
    return resolve(f == null ? null : f.getName());
}

From source file:hrider.io.FileHelper.java

public static File findFile(File folder, Pattern regex) {
    File[] files = folder.listFiles();
    if (files != null) {
        for (File file : files) {
            if (regex.matcher(file.getName()).find()) {
                return file;
            }//  ww  w  .  j  a  v  a  2  s.c  o  m
        }
    }
    return null;
}

From source file:Main.java

public static File[] getSavegames(File folder) {
    File[] files = folder.listFiles();
    ArrayList<File> saveFiles = new ArrayList<File>();
    if (files != null) {
        for (final File fileEntry : files) {
            if (fileEntry.isFile()) {
                if (fileEntry.getName().toLowerCase().endsWith(".lsd")) {
                    saveFiles.add(fileEntry);
                }//from www .  j  a  v a 2s .com
            }
        }
    }
    return saveFiles.toArray(new File[saveFiles.size()]);
}

From source file:com.oldratlee.nanotemplate.NanoTemplateTest.java

@Parameterized.Parameters
public static Collection<Object[]> prepareData() throws Exception {
    final List<Object[]> retTestData = new ArrayList<Object[]>();

    File directory = new File(NanoTemplateTest.class.getResource("./").getFile());
    File[] files = directory.listFiles();
    assertNotNull(files);//from  ww w  . j ava2 s.c o  m
    for (File f : files) {
        if (f.getName().endsWith("nanotemplate")) {
            retTestData.add(new Object[] { f.getName() });
        }
    }
    return retTestData;
}

From source file:com.tyro.oss.pact.spring4.pact.consumer.PactPublisher.java

public static void publishPactFiles(String consumer, String version, String pactFileRoot, String publishUrl)
        throws IOException {
    for (File pactFile : findPactFiles(pactFileRoot)) {
        String provider = pactFile.getName().replace("_pacts.json", "").replace("_", "-");
        publishPactFile(provider, consumer, version, pactFile.getAbsolutePath(), publishUrl);
    }/*from  w  ww  . j a v a  2  s .  c o m*/
}

From source file:Main.java

private static List<Class> findClasses(File directory, String packageName) {
    List<Class> classes = new ArrayList<Class>();
    if (!directory.exists()) {
        return classes;
    }/*from   w  ww.j  a  v a  2 s .  c  om*/
    File[] files = directory.listFiles();
    for (File file : files) {
        if (file.isDirectory()) {
            assert !file.getName().contains(".");
            classes.addAll(findClasses(file, packageName + "." + file.getName()));
        } else if (file.getName().endsWith(".class")) {
            try {
                classes.add(Class
                        .forName(packageName + '.' + file.getName().substring(0, file.getName().length() - 6)));
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        }
    }
    return classes;
}

From source file:FileUtils.java

/**
 * Returns all jpg images from a directory in an array.
 *
 * @param directory                 the directory to start with
 * @param descendIntoSubDirectories should we include sub directories?
 * @return an ArrayList<String> containing all the files or nul if none are found..
 * @throws IOException//from   w ww  .j  av  a 2s  . co  m
 */
public static ArrayList<String> getAllImages(File directory, boolean descendIntoSubDirectories)
        throws IOException {
    ArrayList<String> resultList = new ArrayList<String>(256);
    File[] f = directory.listFiles();
    for (File file : f) {
        if (file != null && file.getName().toLowerCase().endsWith(".jpg")
                && !file.getName().startsWith("tn_")) {
            resultList.add(file.getCanonicalPath());
        }
        if (descendIntoSubDirectories && file.isDirectory()) {
            ArrayList<String> tmp = getAllImages(file, true);
            if (tmp != null) {
                resultList.addAll(tmp);
            }
        }
    }
    if (resultList.size() > 0)
        return resultList;
    else
        return null;
}

From source file:Main.java

/**
 * Recursive method used to find all classes in a given directory and subdirs.
 *
 * @param directory   The base directory
 * @param packageName The package name for classes found inside the base directory
 * @return The classes//from w  w w  .ja  v  a 2  s. com
 * @throws ClassNotFoundException
 */
private static List findClasses(File directory, String packageName) throws ClassNotFoundException {
    List classes = new ArrayList();
    if (!directory.exists()) {
        return classes;
    }
    File[] files = directory.listFiles();
    for (File file : files) {
        if (file.isDirectory()) {
            assert !file.getName().contains(".");
            classes.addAll(findClasses(file, packageName + "." + file.getName()));
        } else if (file.getName().endsWith(".class") && !file.getName().contains("$")
                && !file.getName().endsWith("Test.class")) {
            classes.add(file.getName().substring(0, file.getName().length() - 6));
        }
    }
    return classes;
}