Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

file path

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a question about file location. when I give physical location (for example c:\test\file.txt) for my file path on my local machine. The file can be found and read.
My question is: does it work in DEV or PROD environment? if not, what is the correct path I should give?

Thanks
 
author & internet detective
Posts: 40200
816
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hong Yi wrote:My question is: does it work in DEV or PROD environment?


If you have your files stored in a known location like /mine/properties, this does work. An alternative is to add the directory to your classpath and let Java read them as a resource. If your files are under a server, you have to do this.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DEV or PROD environment in what sense? Is this a web application?
 
Hong Yi
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DEV or PROD is deployed environment. The application is web application. and static files like html will be deployed to web server and dynamic files like jsp will be deployed to application sever.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on how you want to do it, then. Direct client access, no. You'd have to read via absolute path or as Jeanne mentioned and write the response.
 
Hong Yi
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks David and Jeanne. I use the following code:

InputStream is = getClass().getClassLoader().getResourceAsInputStream("fileName") ;

it works on localhost and DEV environment without giving a physical path of the file.

but I still have two questions:

1> how does it find the file?

2>do I need to provide "/" before the fileName like "/fileName"? and why does it work without "/"

Thanks
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It finds the file by looking on the classpath.
 
I have a knack for fixing things like this ... um ... sorry ... here is a consilitory tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic