[Schmitzm-commits] r762 - trunk/src/schmitzm/io

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Mar 11 09:48:01 CET 2010


Author: alfonx
Date: 2010-03-11 09:48:00 +0100 (Thu, 11 Mar 2010)
New Revision: 762

Modified:
   trunk/src/schmitzm/io/IOUtil.java
Log:
Added to IOUtil: 	public static boolean canWriteOrCreate(File file) 
	/**
	 * Similar to {@link File#canWrite()}, but returns <code>true</code> if the
	 * file does not exist but can be created.
	 * 
	 * @param file
	 *            {@link File} to test. May exist or not exist.
	 */


Modified: trunk/src/schmitzm/io/IOUtil.java
===================================================================
--- trunk/src/schmitzm/io/IOUtil.java	2010-03-11 08:45:06 UTC (rev 761)
+++ trunk/src/schmitzm/io/IOUtil.java	2010-03-11 08:48:00 UTC (rev 762)
@@ -743,4 +743,23 @@
 		return null;
 	}
 
+
+	/**
+	 * Similar to {@link File#canWrite()}, but returns <code>true</code> if the
+	 * file does not exist but can be created.
+	 * 
+	 * @param file
+	 *            {@link File} to test. May exist or not exist.
+	 */
+	public static boolean canWriteOrCreate(File file) {
+		if (file.exists())
+			return file.canWrite();
+		try {
+			file.createNewFile();
+			file.delete();
+			return true;
+		} catch (Exception e) {
+			return false;
+		}
+	}
 }



More information about the Schmitzm-commits mailing list