2

Need to upload an image using the relative path, which I would like to run on both IDE and command line.

Here is the code which runs with the absolute path,

         File classpathRoot = new File(System.getProperty("user.dir"));
         File picturesDir = new File(classpathRoot, "/pictures");
         File picture = new File(picturesDir, "profileImage.jpg");
         String picturePath = picture.getAbsolutePath();
ECiurleo
  • 2,043
  • 1
  • 16
  • 45
jass
  • 333
  • 3
  • 5
  • 9
  • So what is your specific issue? Is your code returning an error? – ECiurleo Dec 14 '15 at 14:53
  • How about File file = new File(System.getProperty("user.dir")+"/pictures/profileImage.jpg");String picturePath = file.getAbsolutePath(); ? – Rao Jan 05 '16 at 19:27

1 Answers1

0

You can use . to represent a relative path in your directory

So, if you used something like

classpathRoot, "../pictures"

For more details check here.

http://docs.oracle.com/javase/7/docs/api/java/io/File.html

http://docs.oracle.com/javase/tutorial/essential/io/pathOps.html

ECiurleo
  • 2,043
  • 1
  • 16
  • 45