OSDN Git Service

Add FileUtils with static utility methods for making 'file://' URLs, replacing backsl...
authorNick Clarke <memorius@gmail.com>
Tue, 20 Jul 2010 00:32:53 +0000 (12:32 +1200)
committerRandy Baumgarte <randy@fbn.cx>
Fri, 23 Jul 2010 09:31:05 +0000 (05:31 -0400)
src/cx/fbn/nevernote/utilities/FileUtils.java [new file with mode: 0644]

diff --git a/src/cx/fbn/nevernote/utilities/FileUtils.java b/src/cx/fbn/nevernote/utilities/FileUtils.java
new file mode 100644 (file)
index 0000000..3b9c175
--- /dev/null
@@ -0,0 +1,23 @@
+package cx.fbn.nevernote.utilities;
+
+import java.io.File;
+
+/**
+ * @author Nick Clarke
+ *
+ */
+public final class FileUtils {
+
+    private FileUtils() {}
+
+    public static String toFileURLString(File file) {
+        // NFC TODO: is it safe to use file.toURI().toURL() instead?
+        String prefix = (System.getProperty("os.name").contains("Windows") ? "file:///" : "file://");
+        return prefix + toForwardSlashedPath(file.getAbsolutePath());
+    }
+
+    public static String toForwardSlashedPath(String path) {
+        return path.replace('\\', '/');
+    }
+  
+}