I have a Java Class UpdateStats in WEB-INF/Classes directory of a dynamic web application.This class has a function writeLog() which writes some logs to a text file.I want this text file to be in webcontent directory.Thus everytime the function is called updates stats are written in that text file. The problem is how to give the path of that text file in webcontent directory from within that function,which resides in WEB-INF/Classes directory.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
You can do something like below in your servlet,
When you do
getServletContext().getRealPath()
and put some string argument the file will see at your webcontent location. If you want something into WEB-INF, you can give fileName like "WEB-INF/my_updates.txt".You can get your webapp root directory from ServletContext:
Hope this helps.
To write a file you need to know absolute path of your web content directory on server as file class require absolute path.
Assumption : abc is your project name
WebContent is not any directory when you deploy application. All files under web content goes directly under project name.