Return a full path to an item in the data folder as a File object. See the dataPath() method for more information.
(String where)
| 7312 | * See the dataPath() method for more information. |
| 7313 | */ |
| 7314 | public File dataFile(String where) { |
| 7315 | // isAbsolute() could throw an access exception, but so will writing |
| 7316 | // to the local disk using the sketch path, so this is safe here. |
| 7317 | File why = new File(where); |
| 7318 | if (why.isAbsolute()) return why; |
| 7319 | |
| 7320 | URL jarURL = getClass().getProtectionDomain().getCodeSource().getLocation(); |
| 7321 | // Decode URL |
| 7322 | String jarPath; |
| 7323 | try { |
| 7324 | jarPath = jarURL.toURI().getPath(); |
| 7325 | } catch (URISyntaxException e) { |
| 7326 | e.printStackTrace(); |
| 7327 | return null; |
| 7328 | } |
| 7329 | if (jarPath.contains("Contents/Java/")) { |
| 7330 | File containingFolder = new File(jarPath).getParentFile(); |
| 7331 | File dataFolder = new File(containingFolder, "data"); |
| 7332 | return new File(dataFolder, where); |
| 7333 | } |
| 7334 | // Windows, Linux, or when not using a Mac OS X .app file |
| 7335 | return new File(sketchPath + File.separator + "data" + File.separator + where); |
| 7336 | } |
| 7337 | |
| 7338 | |
| 7339 | /** |
no test coverage detected