java - How to get absolute path of file depends on windows 32-bit or 64-bit machine -


i trying absolute file path on java, when use following code :

file f = new file("..\\webapps\\demoproject\\files\\demo.pdf")   string absolutepath = f.getabsolutepath(); 

it gives correct file path on 32-bit machine

c:\program files\apache software foundation\tomcat6.0\bin\..\webapps\demoproject\files\demo.pdf  

but when run same on 64-bit machine gives filenotfound exception (because of program files(x86)), how correct path regardless of os bit. please help.

i have used below code , giving correct file path have used
system.getproperty("user.dir") current working directory , system.getenv("programfiles") check program files 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 below code getting following path-

on 32-bit
c:\program files\apache software foundation\tomcat6.0\bin\..\webapps\demoproject\files\demo.pdf

on 64-bit
c:\program files (x86)\apache software foundation\tomcat6.0\bin\..\webapps\demoproject\files\demo.pdf


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -