> String configFile = "config.txt";
> i am putting the config file under WEB-INF/classes
> where a java program is accessing it through the
> web.
> but it can't find the config file.
That's because the config file isn't in the current working directory. You need this:input = this.getClass().getResourceAsStream("/config.txt");
The suggestion doesn't work for me. I put the file under the folder called 'CONFIG' under my default-war file of JRUN Server. I try to access the file as such:
String strFilePath = "CONFIG\config.txt";
I access this string under a static variable so I cannot use
"this.getClass().getResourceAsStream("config.txt");"
Any other suggestions? It is important that I use a relative path and not an absolute one. thx
SUGGESTION
"Hi, You can give the relative path like this [code]
String filepath= "textfiles\config.txt"
[\code]
I assume your config.txt file is in the folder textfiles under web-apps folder.
bye for now
sat
"
> The suggestion doesn't work for me. I put the file
> under the folder called 'CONFIG' under my default-war
> file of JRUN Server.
So you didn't really put it in the WEB-INF/classes directory, like you originally said? I don't really see the point of posting false information and then complaining that solutions based on it don't work.
And you're running your code in a static method? I don't really see the point of that in a servlet environment, but whatever. Let's suppose your class is called Stupid. Then put your config file in the WEB-INF/classes directory, because that's in your classpath. Don't put it somewhere else that isn't in the classpath. Then do this:input = Stupid.class.getResourceAsStream("/config.txt");
And forget about the pointless requirement for a "relative" path.
In my application, we are using only one Servlet, ie, MainServlet.
I have declared context as static var in MainServlet as below:-
public static ServletContext context = null;
public void init()
{
context = getServletContext();
String serverPath = context.getRealPath("");
.
.
.
.
}