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 void getStringFromXML(Node node, String dtdFilename, String outputFileName)
        throws TransformerException, IOException {
    File file = new File(outputFileName);
    if (!file.isFile())
        file.createNewFile();//from ww  w .  j  av a 2s  .co m
    BufferedWriter out = new BufferedWriter(new FileWriter(file));

    String workingPath = System.setProperty("user.dir", file.getAbsoluteFile().getParent());
    try {
        getStringFromXML(node, dtdFilename, out);
    } finally {
        System.setProperty("user.dir", workingPath);
    }

    out.flush();
    out.close();
}

From source file:Main.java

/**
 * @param i slot index/*from w  ww.j  av a2  s. c o  m*/
 * @return valid directory of BMI device root
 * @throws IOException 
 */
private static File getBMIDeviceRoot(int i) throws IOException {
    File root = new File("/sys/devices/platform/omap_bmi_slot.$i/bmi/bmi-$i/bmi-dev-$i/".replace("$i", "" + i));

    if (!root.exists() || root.isFile() || root.listFiles().length == 0)
        return null;

    return root;
}

From source file:co.marcin.novaguilds.util.IOUtils.java

public static List<String> getFilesWithoutExtension(File directory) {
    List<String> list = new ArrayList<>();
    File[] filesList = directory.listFiles();

    if (filesList != null) {
        for (File file : filesList) {
            if (file.isFile()) {
                String name = file.getName();
                if (org.apache.commons.lang.StringUtils.contains(name, '.')) {
                    name = org.apache.commons.lang.StringUtils.split(name, '.')[0];
                    list.add(name);/* w  w w  . j  a v  a2s. c om*/
                }
            }
        }
    }

    return list;
}

From source file:Main.java

public static String readStringFromFile(String fileName, boolean addEnterLindEnd) {
    StringBuilder result = new StringBuilder();
    FileInputStream fip = null;/*ww w  .ja  v a2s .c  om*/
    InputStreamReader inputReader = null;
    BufferedReader bufReader = null;
    try {
        File file = new File(fileName);
        if (file.exists() && file.isFile()) {
            fip = new FileInputStream(file);
            inputReader = new InputStreamReader(fip);
            bufReader = new BufferedReader(inputReader);
            String line = "";
            while ((line = bufReader.readLine()) != null) {
                if (addEnterLindEnd) {
                    result.append(line + "\n");
                } else {
                    result.append(line);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (null != bufReader) {
                bufReader.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            if (null != inputReader) {
                inputReader.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            if (null != fip) {
                fip.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return result.toString();
}

From source file:Main.java

public static void deleteFilesInCache() {
    if (filesInCache == null) {
        return;//from ww w .j  av  a2  s  .c o m
    } else {
        for (File file : filesInCache) {
            if (!file.exists())
                continue;
            if (file.isFile()) {
                file.delete();
            } else if (file.isDirectory()) {
                File[] files = file.listFiles();
                for (int i = 0; i < files.length; i++) {
                    if (!files[i].exists())
                        continue;
                    if (files[i].isFile()) {
                        files[i].delete();
                    }
                }
            }
        }
    }
    filesInCache.clear();
}

From source file:com.edduarte.argus.util.Constants.java

public static long folderSize(File directory) {
    long length = 0;
    File[] subFiles = directory.listFiles();
    if (subFiles != null) {
        for (File f : subFiles) {
            length += f.isFile() ? f.length() : folderSize(f);
        }/*from www .  jav  a2s  .  co  m*/
    }
    return length;
}

From source file:com.redhat.akashche.wixgen.cli.Launcher.java

private static WixConfig parseConf(String path) throws IOException {
    File file = new File(path);
    if (!(file.exists() && file.isFile()))
        throw new IOException("Invalid config file: [" + path + "]");
    InputStream is = null;/* w  w  w  . j a v  a2s.c om*/
    try {
        is = new FileInputStream(file);
        Reader re = new InputStreamReader(is, Charset.forName("UTF-8"));
        return new Gson().fromJson(re, WixConfig.class);
    } catch (Exception e) {
        throw new RuntimeException("Invalid config file: [" + path + "]", e);
    } finally {
        closeQuietly(is);
    }
}

From source file:me.dags.creativeblock.blockpack.FolderBlockPack.java

private static IOFileFilter definitionsFilter() {
    return new IOFileFilter() {
        @Override/*  www.  ja v a 2  s . c  om*/
        public boolean accept(File file) {
            return file.isFile();
        }

        @Override
        public boolean accept(File dir, String name) {
            return name.endsWith(".json");
        }
    };
}

From source file:me.dags.creativeblock.blockpack.FolderBlockPack.java

private static IOFileFilter textureFilter() {
    return new IOFileFilter() {
        @Override/*  w  w  w.  ja v a2 s . co  m*/
        public boolean accept(File file) {
            return file.isFile();
        }

        @Override
        public boolean accept(File dir, String name) {
            return name.endsWith(".png");
        }
    };
}

From source file:Main.java

public static void deleteFile2(File file) {

    // Log.i(TAG, "delete file path=" + file.getAbsolutePath());

    if (file.exists()) {
        if (file.isFile()) {
            file.delete();/*  w ww  .j  a  v a2  s  .  c o  m*/
        } else if (file.isDirectory()) {
            File files[] = file.listFiles();
            for (int i = 0; i < files.length; i++) {
                deleteFile2(files[i]);
            }
        }
        file.delete();
    } else {
        // Log.e(TAG, "delete file no exists " + file.getAbsolutePath());
    }
}