Avatar of satmisha
satmisha
Flag for India asked on

what is the way to get get path dynamically as I am getting Getting java.io.FilenotFoundException while using FileStream

Hi Experts,

I am trying to read text file which works great on my local but when I deploy it on server it creates problem because the path on server is different as that of my local.

My Local Path:
   C:\Folder1\Project\File.txt
Server Path:
 C:\F1\F2\F3\F4\Project\File.txt

So in code I have used like this:
 Java.IO.FileINputStream.open +  new FileInputStream("./Project/File.txt")

It works great on my local but fails when I deploy it on server, reason is path.

Is there any way I could make it dynamic so that it could itself detect the right path ?

Looking forward to hearing from you.
Java

Avatar of undefined
Last Comment
mccarl

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
mccarl

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Mark Bullock

You could also use a system property for the path and specify it on the command line
java -Dmypath=C:\Folder1\Project\ MyProgram

Or pass in the path as an argument to your program.
java MyProgram C:\Folder1\Project\ MyProgram
satmisha

ASKER
Apologies for late response. Thanks a lot for your help.
mccarl

You're welcome!
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23