0

String dirPath = fileObj.getParentFile().getAbsolutePath(); system.out.println(dirPath);

I tried this way but its returning the Java Project Path that is Workspace path..

4
  • 2
    how are you creating the fileObj in the first place? Commented Aug 14, 2013 at 8:16
  • @ DhivyaSubramani: Most IDEs change directory to project workspace(or equivalent) before starting applications. Commented Aug 14, 2013 at 8:53
  • File fileObj = new File("aoc test.xls"); like this way i am creating Aakash. Commented Aug 14, 2013 at 9:08
  • What i am asking is by defaulty its returing the Java Project file path and my requirement is i need the Excel file path.. and the file can be stored anywhere in my system. Commented Aug 14, 2013 at 9:10

1 Answer 1

1

.getParentFile() is probably returning the parent directory, which depending on the location of your file could be the project directory. If fileObj is an object of type File, just try using fileObj.getAbsolutePath() instead.

So try this:

File fileObj = new File("myFile.xls");
String dirPath = fileObj.getAbsolutePath();
System.out.println(dirPath);

This should result in output similar to:

C:/[your project directory]/myFile.xls

JavaDoc for getParentFile():

http://docs.oracle.com/javase/1.4.2/docs/api/java/io/File.html#getParentFile()

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you framauro for your response and even i am getting the same error.. :(
Java Path=C:\Documents and Settings\z007981\workspaceSelenium\AOC_CompleteBuild_Copy\20130819_POB$X452SUVP_version.xls;
Java Project Path=C:\Documents and Settings\z007981\workspaceSelenium\AOC_CompleteBuild_Copy\20130819_POB$X452SUVP_version.xls; File Path=d:\LocalData\z007981\Desktop\AocTestFiles\20130819_POB$X452SUVP_version.xls;
In that above post i want to get the File Path.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.