List of usage examples for java.io File canWrite
public boolean canWrite()
From source file:Main.java
public static boolean isValidRoot(String root) { if (TextUtils.isEmpty(root)) return false; File rootFile = new File(root); return rootFile.exists() && rootFile.canRead() && rootFile.canWrite(); }
From source file:Main.java
/** * Get a usable cache directory (external if available, internal otherwise) * * @param context The {@link android.content.Context} to use * @param uniqueName A unique directory name to append to the cache * directory/*from w w w . ja va 2 s . co m*/ * @return The cache directory */ public static File getCacheDir(final Context context, final String uniqueName) { File cachePath = context.getExternalCacheDir(); if (cachePath == null || !cachePath.canWrite()) { cachePath = context.getCacheDir(); } File cacheDir = new File(cachePath, uniqueName); if (!cacheDir.exists()) { cacheDir.mkdirs(); } if (!cacheDir.canWrite()) { cacheDir.setWritable(true); } return cacheDir; }
From source file:Main.java
/** * Get the application folder on the SD Card. Create it if not present. * @return The application folder./* w ww. j a va 2s . c om*/ */ public static File getApplicationFolder() { File root = Environment.getExternalStorageDirectory(); if (root.canWrite()) { File folder = new File(root, APPLICATION_FOLDER); if (!folder.exists()) { folder.mkdir(); } return folder; } else { return null; } }
From source file:Main.java
public static boolean sdCardIsAvailable() { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { File sd = new File(Environment.getExternalStorageDirectory().getPath()); return sd.canWrite(); } else/*from w w w .j av a 2 s .co m*/ return false; }
From source file:eu.ggnet.dwoss.util.TempUtil.java
private static File tryPath(File path, String subPath) { if (path.isDirectory() && path.canWrite()) { File outputPath = new File(path, subPath); if (!outputPath.exists()) { if (!outputPath.mkdirs()) { return null; }//w w w . ja v a2s . c om } else if (!(outputPath.isDirectory() && outputPath.canWrite())) { return null; } return outputPath; } return null; }
From source file:Main.java
public static boolean isExternalStorageWriteable() { boolean writealbe = false; long start = System.currentTimeMillis(); if (TextUtils.equals(Environment.MEDIA_MOUNTED, Environment.getExternalStorageState())) { File esd = Environment.getExternalStorageDirectory(); if (esd.exists() && esd.canWrite()) { File file = new File(esd, ".696E5309-E4A7-27C0-A787-0B2CEBF1F1AB"); if (file.exists()) { writealbe = true;/*from www.j ava 2 s . c o m*/ } else { try { writealbe = file.createNewFile(); } catch (IOException e) { Log.w(TAG, "isExternalStorageWriteable() can't create test file."); } } } } long end = System.currentTimeMillis(); Log.i(TAG, "Utility.isExternalStorageWriteable(" + writealbe + ") cost " + (end - start) + "ms."); return writealbe; }
From source file:Main.java
public static String[] getSecondaryDirs() { List<String> ret = new ArrayList<String>(); String secondaryStorageString = System.getenv("SECONDARY_STORAGE"); if (secondaryStorageString != null && !secondaryStorageString.trim().isEmpty()) { String[] dirs = secondaryStorageString.split(":"); for (String dir : dirs) { File file = new File(dir); if (file.isDirectory() && file.canWrite()) { ret.add(dir);//w ww .j a v a 2 s .c o m } } if (ret.isEmpty()) return null; else return ret.toArray(new String[ret.size()]); } else { return null; } }
From source file:Main.java
public static File getTempDir() { File ext = Environment.getExternalStorageDirectory(); File tempDir = new File(ext, "aquery/temp"); tempDir.mkdirs();/*from w w w. j ava 2 s.c om*/ if (!tempDir.exists() || !tempDir.canWrite()) { return null; } return tempDir; }
From source file:Main.java
private static String getDirPath(Context context) { String dirPath = ""; File photoDir = null;//w ww.ja v a 2s .c o m File extStorageDir = Environment.getExternalStorageDirectory(); if (extStorageDir.canWrite()) { photoDir = new File(extStorageDir.getPath() + "/" + context.getPackageName()); } if (photoDir != null) { if (!photoDir.exists()) { photoDir.mkdirs(); } if (photoDir.canWrite()) { dirPath = photoDir.getPath(); } } return dirPath; }
From source file:MakeDirectories.java
private static void fileData(File f) { System.out.println("Absolute path: " + f.getAbsolutePath() + "\n Can read: " + f.canRead() + "\n Can write: " + f.canWrite() + "\n getName: " + f.getName() + "\n getParent: " + f.getParent() + "\n getPath: " + f.getPath() + "\n length: " + f.length() + "\n lastModified: " + f.lastModified());//from ww w . ja v a 2 s .c o m if (f.isFile()) System.out.println("It's a file"); else if (f.isDirectory()) System.out.println("It's a directory"); }