• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22211
117
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22211
117
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matt Kohanek wrote:nvrmnd ... r-clicked


Could you please Use Real Words next time?
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic