Example usage for java.io File isFile

List of usage examples for java.io File isFile

Introduction

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

Prototype

public boolean isFile() 

Source Link

Document

Tests whether the file denoted by this abstract pathname is a normal file.

Usage

From source file:Main.java

private static boolean clearFile(File file, long date, int day) {
    if ((file != null) && (file.exists()) && (file.isFile())
            && ((date - file.lastModified()) / 86400000L > day)) {
        return file.delete();
    }/*  w w w  .  ja v a2 s. c  om*/
    return false;
}

From source file:Main.java

public static Intent getOpenFileIntent(File file) {
    if (file == null || !file.exists() || !file.isFile()) {
        return null;
    }/*w  w  w.j  a  va2  s.  c om*/
    String extension = MimeTypeMap.getFileExtensionFromUrl(file.getAbsolutePath());
    String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
    if (extension == null || mimeType == null) {
        return null;
    }
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setDataAndType(Uri.fromFile(file), mimeType);
    return intent;
}

From source file:com.webbfontaine.fcvrutilization.utils.FileUtils.java

public static String resolveTableName(File file) {

    if (!file.isFile()) {
        throw new RuntimeException("Not a file: " + file.getName());
    }/*  ww w  .  jav a 2 s  .co  m*/

    if (file.getName().toLowerCase().contains("header")) {
        return "BE_GCNET_HEADER";
    }

    if (file.getName().toLowerCase().contains("item")) {
        return "BE_GCNET_ITEMS";
    }

    throw new RuntimeException("Can not resolve table name by filename");
}

From source file:Main.java

public static boolean checkFile(File f) {
    if (f != null && f.exists() && f.canRead() && (f.isDirectory() || (f.isFile() && f.length() > 0))) {
        return true;
    }//w w w. ja  va 2s . c  o m
    return false;
}

From source file:Main.java

public static boolean checkFileMergedSucc(String mFile) {
    try {/* ww w .  ja  va 2s  . c om*/
        File mergedFile = new File(mFile);
        if (mergedFile != null && mergedFile.isFile() && mergedFile.exists()) {
            return true;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return false;
}

From source file:Main.java

public static void deleteEveryFile(File file) {
    if (file.exists()) {
        if (file.isFile()) {
            file.delete();/*w w w .j a v  a2  s. c  o  m*/
        } else if (file.isDirectory()) {
            File afile[] = file.listFiles();
            if (afile != null) {
                for (int i = 0; i < afile.length; i++)
                    deleteEveryFile(afile[i]);

                file.delete();
            } else {
                file.delete();
            }
        }
    }

}

From source file:Util.java

public static long getFileSizeInBytes(String fileName) {
    long ret = 0;
    File f = new File(fileName);
    if (f.isFile()) {
        return f.length();
    } else if (f.isDirectory()) {
        File[] contents = f.listFiles();
        for (int i = 0; i < contents.length; i++) {
            if (contents[i].isFile()) {
                ret += contents[i].length();
            } else if (contents[i].isDirectory())
                ret += getFileSizeInBytes(contents[i].getPath());
        }//from   w w w. j a v a2 s . c  o m
    }
    return ret;
}

From source file:com.redhat.akashche.keystoregen.Launcher.java

private static KeystoreConfig parseConf(String path) throws IOException {
    File file = new File(path);
    if (!(file.exists() && file.isFile()))
        throw new IOException("Invalid config file: [" + path + "]");
    try (FileInputStream is = new FileInputStream(file)) {
        Reader re = new InputStreamReader(is, Charset.forName("UTF-8"));
        return new Gson().fromJson(re, KeystoreConfig.class);
    } catch (Exception e) {
        throw new RuntimeException("Invalid config file: [" + path + "]", e);
    }/*from w w  w .j av a2 s .  co m*/
}

From source file:Main.java

public static boolean delDir(String dirPath, boolean delFile) {
    if (delFile) {
        File file = new File(dirPath);
        if (file.isFile()) {
            return file.delete();
        } else if (file.isDirectory()) {
            if (file.listFiles().length == 0) {
                return file.delete();
            } else {
                int zfiles = file.listFiles().length;
                File[] delfile = file.listFiles();
                for (int i = 0; i < zfiles; i++) {
                    if (delfile[i].isDirectory()) {
                        delDir(delfile[i].getAbsolutePath(), true);
                    }//from   w  ww  .  j  a v  a  2s. co  m
                    delfile[i].delete();
                }
                return file.delete();
            }
        } else {
            return false;
        }
    } else {
        return new File(dirPath).delete();
    }
}

From source file:Main.java

public static void deleteFile(String fileName) {
    File f = new File(fileName);
    if (f.exists()) {
        if (f.isFile()) {
            f.delete();//from w w  w . j  av a  2  s  .c  o m
        } else if (f.isDirectory()) {
            String[] filelist = f.list();
            for (int i = 0; i < filelist.length; i++) {
                File readfile = new File(fileName + filelist[i]);
                deleteFile(fileName + filelist[i]);
            }
        }
    }
}