DhivyaSubramani
DhivyaSubramani

Reputation: 31

How to get the excel file path using java code

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

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

Upvotes: 0

Views: 5531

Answers (1)

framauro13
framauro13

Reputation: 797

.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()

Upvotes: 1

Related Questions