List of usage examples for java.io File isFile
public boolean isFile()
From source file:Main.java
private static boolean CheckRootingFiles(File... file) { boolean result = false; for (File f : file) { if (f != null && f.exists() && f.isFile()) { result = true;/*from ww w. j a va2 s. com*/ break; } else { result = false; } } return result; }
From source file:Main.java
public static void valiFileIsFile(File file) throws IllegalArgumentException { if (!file.isFile()) { throw new IllegalArgumentException("File:'" + file.getName() + "'does not exist or not file!"); }//from w ww . j a v a 2 s. c o m }
From source file:Main.java
public static void showPicture(Context mContext, String imagePath) { File file = new File(imagePath); if (file != null && file.isFile() == true) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "image/*"); mContext.startActivity(intent);// ww w . j a v a 2s . c om } }
From source file:Main.java
public static boolean isFileExist(String filePath) { if (TextUtils.isEmpty(filePath)) { return false; }/*from w ww.j av a2s . c om*/ File file = new File(filePath); return (file.exists() && file.isFile()); }
From source file:Utils.java
/** * Count files in a directory (including files in all subdirectories) * @param directory the directory to start in * @return the total number of files/*from w w w .ja v a2s .c o m*/ */ public static int countFilesInDirectory(File directory) { int count = 0; for (File file : directory.listFiles()) { if (file.isFile()) { count++; } if (file.isDirectory()) { count += countFilesInDirectory(file); } } return count; }
From source file:Main.java
public static boolean fileExists(String path) { boolean exists = false; if (!TextUtils.isEmpty(path)) { File file = new File(path); exists = file.exists() && file.isFile(); }/*from w w w . j av a 2 s . c om*/ return exists; }
From source file:Main.java
public static String getFileMd5String(File file) { if (!file.isFile()) throw new IllegalArgumentException("only file can calculate MD5 value!"); MessageDigest digest;/*w ww .j a v a 2s.c o m*/ FileInputStream in = null; byte buffer[] = new byte[8192]; int len; try { digest = MessageDigest.getInstance("MD5"); in = new FileInputStream(file); while ((len = in.read(buffer)) != -1) { digest.update(buffer, 0, len); } BigInteger bigInt = new BigInteger(1, digest.digest()); return bigInt.toString(16); } catch (Exception e) { e.printStackTrace(); return null; } finally { try { if (in != null) in.close(); } catch (Exception e) { e.printStackTrace(); } } }
From source file:Main.java
public static boolean existFile(String path, String fileName) { File filePath = new File(path); if (!filePath.isDirectory()) { filePath.mkdirs();/*from ww w .j av a2 s .co m*/ } File file = new File(fileName); if (!file.exists() || !file.isFile()) { return false; } return true; }
From source file:Main.java
private static void delete(File file) throws IOException { if (file.isFile() && file.exists()) { deleteOrThrow(file);//from w ww. ja v a 2s. co m } else { cleanDirectory(file); deleteOrThrow(file); } }
From source file:Main.java
public static boolean install(Context context, File file) { if (file == null || !file.exists() || !file.isFile()) { return false; }/*from w ww. j a v a 2 s.co m*/ Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); return true; }