We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
file paths (Read 806 times)
file paths
Apr 4th, 2010, 7:32pm
 
Okay, so I want to assign a file path to a string, and I want it to be able to just find the file in the same folder that it's in. For example:

What I want:
String af = "sine2.wav";

What I have to use:
String af = "C:/Users/james/Documents/Processing/musicalballs/sine2.wav";

if I don't use the latter, it gives me a NullPointerException.

Can someone help me out with this?
Re: file paths
Reply #1 - Apr 4th, 2010, 10:27pm
 
Put your file (sine2.wav) in a folder named "data" in your sketch folder.

You can also check the "Loading and displaying data" paragraph here:

http://processing.org/learning/gettingstarted/
Re: file paths
Reply #2 - Apr 5th, 2010, 10:16am
 
It's also worth being aware that Processing has two useful related methods:

sketchPath(String)
dataPath(String)

Where the String you pass as an argument is more often than not the file name.  e.g.:

 dataPath("sine2.wav");

would return:

 "C:/Users/james/Documents/Processing/musicalballs/data/sine2.wav";


If you want people to be able to add files to a subfolder of your sketch when exported as an application one option is to use sketchpath (which returns the root folder of your application).  dataPath() is useful to access files that are stored in the datat folder inside the .jar of your exported application...
Re: file paths
Reply #3 - Apr 7th, 2010, 4:10pm
 
Thanks, guys, your help is appreciated Smiley
Page Index Toggle Pages: 1