List of usage examples for java.io File canWrite
public boolean canWrite()
From source file:com.manydesigns.elements.util.ElementsFileUtils.java
public static boolean ensureDirectoryExistsAndWarnIfNotWritable(File file) { logger.debug("Ensure directory exists and writable: {}", file); if (!ensureDirectoryExists(file)) return false; try {//from w w w . j a v a 2 s.c om if (!file.canWrite()) { logger.warn("Directory not writable: {}", file); } else { logger.debug("Success"); } } catch (Exception e) { logger.warn("Directory not writable: " + file, e); } return true; }
From source file:com.binomed.showtime.android.util.CineShowTimeLayoutUtils.java
public static InputStream manageFile(String urlImg, String fileName) { InputStream stream = null;/*from w ww . j av a 2s. co m*/ try { File root = Environment.getExternalStorageDirectory(); if (root.canWrite()) { if (fileName == null) { fileName = urlImg.substring(urlImg.lastIndexOf("/"), urlImg.length()); } File posterFile = new File(root, new StringBuilder(CineShowtimeCst.FOLDER_POSTER).append(fileName).toString()); posterFile.getParentFile().mkdirs(); if (posterFile.exists()) { Log.i(TAG, "img existe"); stream = new FileInputStream(posterFile); } else { Log.i(TAG, "img existe pas : lancement de la requete"); HttpGet getMethod = new HttpGet(); getMethod.setURI(new URI(urlImg)); HttpResponse res = new DefaultHttpClient().execute(getMethod); FileOutputStream fileOutPut = new FileOutputStream(posterFile); InputStream inputStream = res.getEntity().getContent(); byte[] tempon = new byte[10240]; while (true) { int nRead = inputStream.read(tempon, 0, tempon.length); if (nRead <= 0) { break; } fileOutPut.write(tempon, 0, nRead); } fileOutPut.close(); stream = new FileInputStream(posterFile); // movie.setImgStream(); } } else { Log.i(TAG, "SD not accessible : " + urlImg); HttpGet getMethod = CineShowtimeFactory.getHttpGet(); getMethod.setURI(new URI(urlImg)); HttpResponse res = CineShowtimeFactory.getHttpClient().execute(getMethod); stream = res.getEntity().getContent(); } } catch (IOException e) { Log.e(TAG, "Could not write file " + e); //$NON-NLS-1$ } catch (URISyntaxException e) { Log.e(TAG, "Could not write file " + e); //$NON-NLS-1$ } return stream; }
From source file:com.zotoh.core.util.FileUte.java
/** * @param fp/*from w w w .j a v a 2 s . co m*/ * @return */ public static boolean isFileKosher(File fp) { return fp != null && fp.exists() && fp.canRead() && fp.canWrite(); }
From source file:net.sourceforge.ganttproject.gui.options.InterfaceOptionPageProvider.java
private static File getExtDir() { File fallback = new File(System.getProperty("java.home"), Joiner.on(File.separatorChar).join("lib", "ext")); String extDirsProperty = System.getProperty("java.ext.dirs"); if (Strings.isNullOrEmpty(extDirsProperty)) { return fallback; }/*from w w w. j ava 2 s . c om*/ for (String s : extDirsProperty.split(File.pathSeparator)) { File file = new File(s); if (!file.exists()) { continue; } if (!file.isDirectory()) { continue; } if (file.canWrite()) { return file; } fallback = file; } return fallback; }
From source file:Main.java
/** Copy folders */ private static boolean copyDir(File srcDir, File dstDir) { if (dstDir.exists()) { if (dstDir.isDirectory() == false) { return false; }//from w w w. j a va 2 s . co m } else { if (dstDir.mkdirs() == false) { return false; } } if (dstDir.canWrite() == false) { return false; } File[] files = srcDir.listFiles(); if (files == null) { return false; } for (int i = 0; i < files.length; i++) { File dstFile = new File(dstDir, files[i].getName()); if (files[i].isDirectory()) { copyDir(files[i], dstFile); } else { copyFile(files[i], dstFile); } } return true; }
From source file:it.geosolutions.geoserver.jms.configuration.JMSConfiguration.java
public final static File getTempDir() { String tempPath = ApplicationProperties.getProperty(WebUtils.TEMP_DIR_CONTEXT_ATTRIBUTE); if (tempPath == null) { return null; }//w ww. j a v a 2s. c om File tempDir = new File(tempPath); if (tempDir.exists() == false) return null; if (tempDir.isDirectory() == false) return null; if (tempDir.canWrite() == false) return null; return tempDir; }
From source file:adalid.commons.util.FilUtils.java
public static boolean isWritableFile(File file) { return file != null && file.isFile() && file.canWrite(); }
From source file:com.zotoh.core.util.FileUte.java
/** * @param dir/*w ww . j a v a 2 s . c o m*/ * @return */ public static boolean isDirKosher(File dir) { return dir != null && dir.exists() && dir.canExecute() && dir.canRead() && dir.canWrite(); }
From source file:adalid.commons.util.FilUtils.java
public static boolean isWritableDirectory(File file) { return file != null && file.isDirectory() && file.canWrite(); }
From source file:FileTableHTML.java
public static String makeHTMLTable(String dirname) { // Look up the contents of the directory File dir = new File(dirname); String[] entries = dir.list(); // Set up an output stream we can print the table to. // This is easier than concatenating strings all the time. StringWriter sout = new StringWriter(); PrintWriter out = new PrintWriter(sout); // Print the directory name as the page title out.println("<H1>" + dirname + "</H1>"); // Print an "up" link, unless we're already at the root String parent = dir.getParent(); if ((parent != null) && (parent.length() > 0)) out.println("<A HREF=\"" + parent + "\">Up to parent directory</A><P>"); // Print out the table out.print("<TABLE BORDER=2 WIDTH=600><TR>"); out.print("<TH>Name</TH><TH>Size</TH><TH>Modified</TH>"); out.println("<TH>Readable?</TH><TH>Writable?</TH></TR>"); for (int i = 0; i < entries.length; i++) { File f = new File(dir, entries[i]); out.println("<TR><TD>" + (f.isDirectory() ? "<a href=\"" + f + "\">" + entries[i] + "</a>" : entries[i]) + "</TD><TD>" + f.length() + "</TD><TD>" + new Date(f.lastModified()) + "</TD><TD align=center>" + (f.canRead() ? "x" : " ") + "</TD><TD align=center>" + (f.canWrite() ? "x" : " ") + "</TD></TR>"); }/*from w ww . j a v a2s . c o m*/ out.println("</TABLE>"); out.close(); // Get the string of HTML from the StringWriter and return it. return sout.toString(); }