Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning 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
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

trying to use a .txt or .properties file to store variables that change often

 
Village Idiot
Posts: 484
jQuery Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried a few things to do this GWT, didnt work, and then I made a .txt file with the assignments, and used java.util.Properties to so this. It works at times and at others does not is the problem. When I do a PutMethod to one of these variables stored in the .txt file through eclipse, running it as a java app, it works fine, it finds the ConstantVariables.txt file and goes through the keys to find the correct variable.

But when I try to do this through a a webpage, and not as a java app, I get a message telling me it cannot find the entity WebContent/ConstantVariables.txt, or something along those lines. Its probably an issue with Tomcat not putting the .txt file in the right place or something like that, Tomcat always gives me problems...

Can someone tell me where the problem may be coming from? Or if there is just a simpler way to do this? Right now I have to put in code to load up the .txt file and name it p, and then to p.getKey("variableName"), and such. Is there just a way to make a .properties file, and do some kind of import or something in the java code, where I can just use variableName instead of the whole p.get("variableName") stuff? It seems like this would be something that us used often and that there should be an easier way than needing all this extra code to do this,

But the main problem is the first I mentioned, that when I try to use this through webpages it doesnt find the .txt file.

Any ideas/tips/help?
 
Sheriff
Posts: 21922
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use ServletContext.getRealPath when you're using servlets / JSP pages. This will be relative to the web app folder. For instance, inside a servlet, the following will print something like "C:\Program Files\Apache\Tomcat\webapps\myWepApp\WEB-INF\myFile.properties":
 
Matt Kohanek
Village Idiot
Posts: 484
jQuery Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
edit - nevermind, instead of using that I just went to the necessary file right-clicked and went to properties to see the full path name laughing out loud - easier than trying to figure out why I couldnt make the above line of code work

fixed - laughing out loud

 
Rob Spoor
Sheriff
Posts: 21922
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Matt Kohanek wrote:nvrmnd ... r-clicked


Could you please Use Real Words next time?
 
Try 100 things. 2 will work out, but you will never know in advance which 2. This tiny ad might be one:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic