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 void deleteFlie(String path) {
    if (TextUtils.isEmpty(path)) {
        return;//from w w w .  j  a v a 2 s  .c o  m
    }
    File filePath = new File(path);
    File[] itemList = filePath.listFiles();
    long totalSize = 0;
    if (null != itemList) {
        for (File f : itemList) {
            if (f.exists() && f.isFile()) {
                f.delete();
            }
        }
    }
}

From source file:Main.java

public static void deleteFiles(List<File> selectedFiles) {
    if (selectedFiles != null & selectedFiles.size() > 0) {
        for (File file : selectedFiles) {
            if (file.isFile()) {
                file.delete();// w w  w .j  a  v  a  2 s . c  o  m
            } else {
                deleteDir(file);
                //               file.delete();
            }
        }
    }
}

From source file:Main.java

public static boolean deleteFolder(File folder) {
    if (!folder.exists()) {
        return true;
    }//from  w  w w  .j  a  v  a2 s  . c om

    File[] subFiles = folder.listFiles();
    if (subFiles != null) {
        for (File f : subFiles) {
            if (f.isFile()) {
                if (!f.delete()) {
                    return false;
                }
            } else {
                if (!deleteFolder(f)) {
                    return false;
                }
            }
        }
    }

    return folder.delete();

}

From source file:Main.java

public static int getFileLines(File file) {
    if (!file.canRead() || !file.isFile()) {
        Log.w(LOG_TAG, CLASS + ": getLinesInFile: invalid file.");
        return -1;
    }//  ww  w. j  av a  2  s.  c om

    int lines = 0;
    try {
        BufferedReader reader = new BufferedReader(new FileReader(file));
        while (reader.readLine() != null)
            lines++;
        reader.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

    return lines;
}

From source file:Main.java

private static boolean checkApkFile(String apkPath) {
    if (apkPath == null || apkPath.length() == 0) {
        return false;
    }/*  ww w.  j a v  a 2  s . c o m*/

    File apkFile = new File(apkPath);
    return !(!apkFile.exists() || !apkFile.isFile());
}

From source file:Main.java

/**
 * //from ww w  . j  a va  2  s  .co  m
 * @param filename
 * @return
 */
public static long getFileSize(String filename) {
    File file = new File(filename);
    if (!file.exists() || !file.isFile()) {
        Log.e(TAG, "GETFILESIZE: File \"" + filename + "\" doesn\'t exist");
        return -1;
    }
    return (file.length() / 1024);
}

From source file:Main.java

/**
 * Gets the opf file name./*  ww w . j  av a 2  s .c  o m*/
 * 
 * @param path the folder contains file opf.
 * @return the opf file name
 */
public static String getOpfFileName(String path) {
    String fileName = null;
    File folder = new File(path);
    if (folder.isDirectory()) {
        File[] listOfFiles = folder.listFiles();
        if (listOfFiles != null) {
            for (File file : listOfFiles) {
                if (file.isFile() && file.getName().endsWith(".opf")) {
                    fileName = file.getName();
                    break;
                }
            }
        }
    }
    return fileName;
}

From source file:Main.java

public static void deleteFile(File file) {
    try {/*  ww  w  .java2  s  . co  m*/
        if (file != null && file.isFile() && file.exists()) {
            file.delete();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static boolean isExistFile(String fileName) {
    if (TextUtils.isEmpty(fileName)) {
        return false;
    }/* w w w.j  a va2 s .c o m*/

    File file = new File(fileName);
    if (file.exists() && file.isFile()) {
        return true;
    }

    return false;
}

From source file:Main.java

private static long getFileSize(String path) {
    if (TextUtils.isEmpty(path)) {
        return 0;
    }/*from   w w  w .  j  a v  a  2s. co  m*/
    File filePath = new File(path);
    File[] itemList = filePath.listFiles();
    long totalSize = 0;
    if (null != itemList) {
        for (File f : itemList) {
            if (f.exists() && f.isFile() && f.length() > 0) {
                totalSize = totalSize + f.length();
            }
        }
    }
    return totalSize;
}