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

/**
 * Tests if a folder is a RPG2k Game.//from  ww  w.ja v a2  s  .  c  om
 * (contains DATABASE_NAME and TREEMAP_NAME)
 *
 * @param dir Directory to test
 * @return true if RPG2k game
 */
public static boolean isRpg2kGame(File dir) {
    if (!dir.isDirectory() || !dir.canRead()) {
        return false;
    }

    boolean databaseFound = false;
    boolean treemapFound = false;

    for (File entry : dir.listFiles()) {
        if (entry.isFile() && entry.canRead()) {
            if (!databaseFound && entry.getName().equalsIgnoreCase(DATABASE_NAME)) {
                databaseFound = true;
            } else if (!treemapFound && entry.getName().equalsIgnoreCase(TREEMAP_NAME)) {
                treemapFound = true;
            }

            if (databaseFound && treemapFound) {
                return true;
            }
        }
    }

    return false;
}

From source file:Main.java

public static JFileChooser generateFileChooser(String description, String... ext) {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setFileFilter(new FileFilter() {
        @Override/*from   www  .  j  a v a2 s  . c om*/
        public boolean accept(File f) {
            boolean res = f.isDirectory();
            for (String s : ext) {
                res = res || f.getName().endsWith("." + s);
            }
            return res;
        }

        @Override
        public String getDescription() {
            return description;
        }

    });
    return fileChooser;
}

From source file:de.uni.bremen.monty.moco.CompileFilesBaseTest.java

protected static Collection<Object[]> buildParameterObject(Collection<File> programFiles) {
    Object[][] a = new Object[programFiles.size()][1];
    int i = 0;/* ww w  .  j  a va2s.c  o  m*/
    for (File programFile : programFiles) {
        a[i++] = new Object[] { programFile, programFile.getName() };
    }
    return Arrays.asList(a);
}

From source file:Main.java

public static void copyAsset(Context context, AssetManager am, boolean force) {
    File newDir = getSDDir(context);
    File sd = Environment.getExternalStorageDirectory();
    if (sd != null && sd.exists() && sd.isDirectory() && newDir.exists() && newDir.isDirectory()) {
        File hpDir = new File(sd, ".hp48");
        if (hpDir.exists()) {
            File allFiles[] = hpDir.listFiles();
            if (allFiles != null && allFiles.length > 0) {
                Log.i("x48",
                        "Moving x48 files from the old dir " + sd.getAbsolutePath() + " to the proper one :");
                for (File file : allFiles) {
                    File newFile = new File(newDir, file.getName());
                    Log.i("x48", "Moving " + file.getAbsolutePath() + " to " + newFile);
                    file.renameTo(newFile);
                }//from  w  w w  .j  av a2s . c  o m
            }
            Log.i("x48", "Deleting old directory");
            hpDir.delete();
        }
    }
    copyAsset(am, newDir, force);
}

From source file:Main.java

public static void valiFileIsDirectory(File file) throws IllegalArgumentException {
    if (!file.isDirectory()) {
        throw new IllegalArgumentException("File:'" + file.getName() + "'does not exist or not directory!");
    }//from  ww  w  .  ja  v  a 2  s.  co m
}

From source file:Main.java

/**
 * Creates a thumbnail file starting from an image/video file
 *
 * @param original_file original file path
 * @param video         true if the file is a video. false if the file is a picture
 * @return a file/* w  w w  .  ja  va  2 s  . c  o m*/
 */
private static File generateThumbnailFileForFile(File original_file, boolean video) {
    // Create an image file name
    try {
        String imageFileName = "thumb" + original_file.getName();
        Log.d(TAG, original_file.getName());
        File storageDir = Environment.getExternalStoragePublicDirectory(
                video ? Environment.DIRECTORY_MOVIES : Environment.DIRECTORY_PICTURES);
        return File.createTempFile(imageFileName, /* prefix */
                THUMB_FORMAT_EXTENSION, /* suffix */
                storageDir /* directory */
        );
    } catch (IOException e) {
        Log.d(TAG, "Error", e);
    }
    return null;

}

From source file:com.starit.diamond.utils.AppNameUtils.java

private static boolean inExcludes(File file, String[] excludes) {
    for (String exclude : excludes) {
        if (file.getName().equalsIgnoreCase(exclude)) {
            return true;
        }/*from   ww w .  j  av  a  2  s . c  o  m*/
    }
    return false;
}

From source file:Main.java

public static File ungzip(File gzip, File toDir) throws IOException {
    toDir.mkdirs();//from   w w  w.ja va 2  s. c o  m
    File out = new File(toDir, gzip.getName());
    GZIPInputStream gin = null;
    FileOutputStream fout = null;
    try {
        FileInputStream fin = new FileInputStream(gzip);
        gin = new GZIPInputStream(fin);
        fout = new FileOutputStream(out);
        copy(gin, fout);
        gin.close();
        fout.close();
    } finally {
        closeQuietly(gin);
        closeQuietly(fout);
    }
    return out;
}

From source file:com.wavemaker.tools.ws.WSDLTest.java

private static List<com.wavemaker.tools.io.File> convertToFileSystemFileList(List<File> files) {
    List<com.wavemaker.tools.io.File> rtn = new ArrayList<com.wavemaker.tools.io.File>();
    for (File file : files) {
        rtn.add(new LocalFolder(file.getParent()).getFile(file.getName()));
    }/*from   w w w. j  a v a 2s  .  co  m*/
    return rtn;
}

From source file:eu.europa.esig.dss.applet.util.FileTypeDetectorUtils.java

private static boolean isASiCS(final File file) {
    return file.getName().toLowerCase().endsWith(".asics");
}