Return a full path to an item in the data folder as a File object. See the dataPath() method for more information.
(String where)
| 8105 | * See the dataPath() method for more information. |
| 8106 | */ |
| 8107 | public File dataFile(String where) { |
| 8108 | // isAbsolute() could throw an access exception, but so will writing |
| 8109 | // to the local disk using the sketch path, so this is safe here. |
| 8110 | File why = new File(where); |
| 8111 | if (why.isAbsolute()) return why; |
| 8112 | |
| 8113 | URL jarURL = getClass().getProtectionDomain().getCodeSource().getLocation(); |
| 8114 | // Decode URL |
| 8115 | String jarPath; |
| 8116 | try { |
| 8117 | jarPath = jarURL.toURI().getPath(); |
| 8118 | } catch (URISyntaxException e) { |
| 8119 | e.printStackTrace(); |
| 8120 | return null; |
| 8121 | } |
| 8122 | if (jarPath.contains("Contents/Java/")) { |
| 8123 | File containingFolder = new File(jarPath).getParentFile(); |
| 8124 | File dataFolder = new File(containingFolder, "data"); |
| 8125 | return new File(dataFolder, where); |
| 8126 | } |
| 8127 | // Windows, Linux, or when not using a Mac OS X .app file |
| 8128 | File workingDirItem = |
| 8129 | new File(sketchPath + File.separator + "data" + File.separator + where); |
| 8130 | // if (workingDirItem.exists()) { |
| 8131 | return workingDirItem; |
| 8132 | // } |
| 8133 | // // In some cases, the current working directory won't be set properly. |
| 8134 | } |
| 8135 | |
| 8136 | |
| 8137 | /** |
no test coverage detected