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:com.wendal.java.dex.decomplier.toolkit.IO_Tool.java

@SuppressWarnings("unchecked")
public static List<String> getFile(String filepath) throws IOException {
    if (filepath != null) {
        File file = new File(filepath);
        if (file.exists() && file.isFile()) {
            return FileUtils.readLines(file);
        }//from w w w . ja v  a2s .c om
    }
    /*null*/
    return null;
}

From source file:Main.java

public static boolean createFile(String name) {
    File outfile = new File(name);
    BufferedWriter writer = null;
    if (!outfile.isFile()) {
        try {//from   w w  w .ja v  a2  s  . co  m
            outfile.createNewFile();
            writer = new BufferedWriter(new FileWriter(outfile));
            writer.write(
                    "#_*_ coding: iso8859_1\n# Script API\n\nfrom com.android.python import AndroidDriver\n\n");
            writer.flush();
            return true;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            try {
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return false;
}

From source file:Main.java

public static boolean deleteFile(String path) {
    boolean result = false;
    if (!TextUtils.isEmpty(path)) {
        File file = new File(path);
        if (file.exists()) {
            if (file.isFile()) {
                result = file.delete();/*w w  w.  j  a v  a  2 s .  c o m*/
            } else {
                result = removeDir(file);
            }
        }
    }
    return result;
}

From source file:com.pnf.jebauto.AutoUtil.java

private static void retrieveFilesRecurse(File f, List<File> results) {
    if (f.isFile()) {
        results.add(f);/*from   w ww .  j  a  v a  2s.c o m*/
    } else {
        for (String name : f.list()) {
            File f1 = new File(f, name);
            retrieveFilesRecurse(f1, results);
        }
    }
}

From source file:Main.java

public static File getSharedPreferencesFile(Context context, String prefFilename) {
    final ApplicationInfo applicationInfo = context.getApplicationInfo();
    if (applicationInfo == null)
        return null;
    if (applicationInfo.dataDir == null)
        return null;
    final File dataDir = new File(applicationInfo.dataDir);
    final File sharedPrefsDir = new File(dataDir, "shared_prefs");

    final String filename = prefFilename == null ? applicationInfo.packageName + "_preferences.xml"
            : prefFilename;/*from  ww  w  . j a va  2s  .c o m*/
    final File sharedPrefFile = new File(sharedPrefsDir, filename);
    return sharedPrefFile.exists() && sharedPrefFile.isFile() ? sharedPrefFile : null;
}

From source file:Main.java

public static boolean deleteFileOrDir(File path) {
    if (path == null || !path.exists()) {
        return true;
    }/*  w w w .  j  a v  a 2s  . c om*/
    if (path.isFile()) {
        return path.delete();
    }
    File[] files = path.listFiles();
    if (files != null) {
        for (File file : files) {
            deleteFileOrDir(file);
        }
    }
    return path.delete();
}

From source file:Main.java

public static boolean addByte(@NonNull File fileName, @NonNull String content) {
    if (!fileName.isFile()) {
        return false;
    }// w  ww  .j a v a 2  s  .c o  m
    OutputStream out = null;
    try {
        out = new FileOutputStream(fileName, true);
        byte[] b = content.getBytes();
        for (int i = 0; i < b.length; i++) {
            out.write(b[i]);
        }
        return true;
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    } catch (Exception e) {
        return false;
    } finally {
        CloseableClose(out);
    }
}

From source file:Main.java

/**
 * Get the list of xml files in the bookmark export folder.
 * @return The list of xml files in the bookmark export folder.
 *///from w  w  w .  jav a 2s  .c  om
public static List<String> getExportedBookmarksFileList() {
    List<String> result = new ArrayList<String>();

    File folder = Environment.getExternalStorageDirectory();

    if (folder != null) {

        FileFilter filter = new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                if ((pathname.isFile()) && (pathname.getPath().toLowerCase(Locale.US).endsWith(".xml")
                        || pathname.getPath().toLowerCase(Locale.US).endsWith(".json"))) {
                    return true;
                }
                return false;
            }
        };

        File[] files = folder.listFiles(filter);

        for (File file : files) {
            result.add(file.getName());
        }
    }

    Collections.sort(result, new Comparator<String>() {

        @Override
        public int compare(String arg0, String arg1) {
            return arg1.compareTo(arg0);
        }
    });

    return result;
}

From source file:com.ibm.liberty.starter.StarterUtil.java

/**
 * Generate the list of files in the directory and all of its sub-directories (recursive)
 * //from w w  w .  j  a  va 2  s  .c  o  m
 * @param dir - The directory
 * @param filesListInDir - List to store the files
 */
public static void populateFilesList(File dir, List<File> filesListInDir) {
    File[] files = dir.listFiles();
    for (File file : files) {
        if (file.isFile()) {
            filesListInDir.add(file);
        } else {
            populateFilesList(file, filesListInDir);
        }
    }
}

From source file:fm.moe.android.util.JSONFileHelper.java

public static JSONObject read(final String path) throws IOException, JSONException {
    if (path == null)
        throw new FileNotFoundException();
    final File file = new File(path);
    if (!file.isFile())
        throw new FileNotFoundException();
    return new JSONObject(readFile(file));
}