I used the code below and it gives the correct path to the file where I used System.getProperty("user.dir") to get the current working directory and System.getenv("ProgramFiles") to check the program file name.
`
String downloadDir = "..\\webapps\\demoproject\\files"; String currentdir = System.getProperty("user.dir"); String programFiles = System.getenv("ProgramFiles"); String filePath = ""; if(programFiles.equals("C:\\Program Files")) { filePath = currentdir + "\\" + downloadDir + "\\demo.pdf"; } else { filePath = currentdir + "\\" + "bin"+ "\\" + downloadDir + "demo.pdf"; } File pdfFile = new File(filePath); String absolutePath = pdfFile.getAbsolutePath(); System.out.println(absolutePath);
`
After executing the below code, I get the following path:
In 32-bit version
C:\Program Files\Apache Software Foundation\Tomcat6.0\bin\..\webapps\demoproject\files\demo.pdf
In the 64-bit version
C:\Program Files (x86)\Apache Software Foundation\Tomcat6.0\bin\..\webapps\demoproject\files\demo.pdf
source share