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

public static String readFromFile(String path) {
    String str = null;/*from  www.ja  v a2  s  .c o m*/
    if (path == null || path.trim().length() == 0) {
        return null;
    }

    File file = new File(path);

    if (file.exists() && file.isFile()) {
        int filelength = (int) file.length();
        byte[] filecontent = new byte[filelength];
        try {
            FileInputStream in = new FileInputStream(file);
            in.read(filecontent);
            in.close();
            str = new String(filecontent, "UTF-8");

        } catch (Exception e) {
            Log.v(TAG, "read file is error");
            return null;
        }

    }
    return str;
}

From source file:Main.java

public static NodeList getNodesByXPath(File file, String xpath) {
    if (!file.isFile() || !file.canRead())
        return null;

    Document document;//from   w w w .j  a v  a  2s .  c o  m
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();

    try {
        DocumentBuilder documentBuilder = dbFactory.newDocumentBuilder();
        document = documentBuilder.parse(file);
    } catch (ParserConfigurationException e) {
        return null;
    } catch (SAXException e) {
        return null;
    } catch (IOException e) {
        return null;
    }

    if (document == null) {
        return null;
    }

    Object result;
    try {
        XPath xpathCompiler = XPathFactory.newInstance().newXPath();
        XPathExpression xPathExpr = xpathCompiler.compile(xpath);
        result = xPathExpr.evaluate(document, XPathConstants.NODESET);
    } catch (XPathExpressionException e) {
        return null;
    }

    return (NodeList) result;
}

From source file:com.docudile.app.services.utils.FileHandler.java

private static ArrayList<String> getFilePaths(String folderPath) {
    ArrayList<String> filenames = new ArrayList<>();
    File folder = new File(folderPath);

    for (File filename : folder.listFiles()) {
        if (filename.isFile()) {
            filenames.add(filename.getName());
        }/*from ww w . ja va  2 s .  c  om*/
    }
    return filenames;
}

From source file:com.px100systems.data.utility.BackupFile.java

public static boolean isBackup(File file) {
    return file.isFile() && file.getName().endsWith(EXTENSION);
}

From source file:libepg.common.tsfile.TsFile.java

/**
 * ?????????/*from  ww  w.  j  a  v a 2 s.c  o m*/
 * ????????????????????????
 *
 * @return ??
 */
public static File getTsFile() {
    File f = new File(TS_FILE_NAME);
    if (!f.isFile()) {
        LOG.error(
                "?ts?????????????? = "
                        + TS_FILE_NAME);
    }
    assumeTrue(f.isFile());
    return f;
}

From source file:by.heap.remark.util.TestUtils.java

/**
 * Reads a resource into a string.//from   w  w w  .ja  v a  2s  . co  m
 * @param path Path to resource
 * @return String contents of resource
 */
public static String readResourceToString(String path) {
    String result;
    try {
        URL u = StringUtils.class.getResource(path);
        if (u == null) {
            throw new Exception("Resource not found");
        }
        File f = FileUtils.toFile(u);
        if (!f.isFile()) {
            throw new Exception("Resource file does not exist or is not a file.");
        }
        result = FileUtils.readFileToString(f, "UTF-8");
        if (result == null) {
            throw new Exception("Error reading resource file.");
        }
    } catch (Exception e) {
        e.printStackTrace();
        result = "UNABLE TO LOAD RESOURCE " + path + ": " + e.getMessage();
    }
    return result;
}

From source file:Main.java

static List<File> recursiveGetFile(File f, FileFilter ff) {
    List<File> lf = new ArrayList<File>();
    if (f.isFile()) {
        if (ff.accept(f)) {
            lf.add(f);/*w w  w  .java 2s  . c  o  m*/
        }
    } else {
        File[] fs = f.listFiles();
        for (File tempF : fs) {
            lf.addAll(recursiveGetFile(tempF, ff));
        }
    }
    return lf;
}

From source file:Main.java

/**
 * @author Ian Copland/*from  w w  w.  ja v  a 2 s.c  o  m*/
 *
 * @param in_filePath - The file path.
 *
 * @return whether or not the given path exists.
 */
public static boolean doesFileExist(String in_filePath) {
    File file = new File(in_filePath);
    if (file.exists() == true && file.isFile() == true) {
        return true;
    }
    return false;
}

From source file:Main.java

public static boolean deleteFile(String path) {
    if (TextUtils.isEmpty(path)) {
        return true;
    }/*from w w  w.  j  a  v  a 2 s  . c o m*/

    File file = new File(path);
    if (file.exists()) {
        if (file.isFile()) {
            return file.delete();
        } else if (file.isDirectory()) {
            for (File f : file.listFiles()) {
                if (f.isFile()) {
                    f.delete();
                } else if (f.isDirectory()) {
                    deleteFile(f.getAbsolutePath());
                }
            }
            return file.delete();
        }
        return false;
    }
    return true;
}

From source file:Main.java

public static byte[] readBytesFromFile(File file) {
    if (file != null && file.exists() && file.isFile()) {
        int filelength = (int) file.length();
        byte[] filecontent = new byte[filelength];
        try {//from  ww w.  ja v a 2 s.  c  o m
            FileInputStream in = new FileInputStream(file);
            in.read(filecontent);
            in.close();

        } catch (Exception e) {
            Log.v(TAG, "read file is error");
            return null;
        }
        return filecontent;
    }
    return null;
}