0

I want to read the files by using relative path and writing the content into destination file using the relative path. Suppose i have the file in my D:/Projects/MyProjects/SuppotTools/internal-file.xml.

I want to read the above file using relative path like:

File file = new File("/../../internal-file.xml")

and same thing i want to write into the destination folder:

D:/Projects/MyProjects/SuppotTools/processed-files/internal-file.xml.

using relative path.

Could any body tell me how to do it?

Onel Sarmiento
  • 1,608
  • 3
  • 20
  • 46
M.S.Naidu
  • 2,239
  • 5
  • 32
  • 56
  • 1
    `Relative paths` are used to point only you project `folder/directory` not whole PC. If you want to point toward the different `drives` then the only answer is you have to specify qualified path. – Vighanesh Gursale Nov 07 '14 at 08:39
  • 1
    If you are using Java 7+, I recommend you take a look at the new methodolgy to handle I/O, which revolves around the Path class. http://docs.oracle.com/javase/tutorial/essential/io/fileio.html – DSquare Nov 07 '14 at 08:40
  • yes @VighaneshGursale thats right, I want to use the relative path like i said above in my project not particularly in my pc, because this project could be in different drive in others developer's pc. – M.S.Naidu Nov 07 '14 at 08:41
  • @M.S.Naidu in your case you are specifying different path and note, the file which you want to use is not stored inside your project. The relative path is only works with projects. Consider you have project `abc` and your file is in `resources` folder then you need to write `File(/resources/yourfilename)`; – Vighanesh Gursale Nov 07 '14 at 08:46
  • Thank you @VighaneshGursale Could you please look into my exact requirement which is in http://stackoverflow.com/questions/26777338/use-relative-path-in-place-of-absolute-path – M.S.Naidu Nov 07 '14 at 08:49
  • D:\SDC-Builds\SRDM2.3.0.6904.10\SRDM\Svr this is the actual parent path from my pc if it is some other's pc it could be E:\SDC\SRDM2.3.0.6904.10\SRDM\Svr. So i don't want to use the base path while reading and writing a file – M.S.Naidu Nov 07 '14 at 08:56

0 Answers0