OSDN Git Service

Add FileUtils with static utility methods for making 'file://' URLs, replacing backsl...
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / utilities / FileUtils.java
1 package cx.fbn.nevernote.utilities;
2
3 import java.io.File;
4
5 /**
6  * @author Nick Clarke
7  *
8  */
9 public final class FileUtils {
10
11     private FileUtils() {}
12
13     public static String toFileURLString(File file) {
14         // NFC TODO: is it safe to use file.toURI().toURL() instead?
15         String prefix = (System.getProperty("os.name").contains("Windows") ? "file:///" : "file://");
16         return prefix + toForwardSlashedPath(file.getAbsolutePath());
17     }
18
19     public static String toForwardSlashedPath(String path) {
20         return path.replace('\\', '/');
21     }
22   
23 }