can't find file

String configFile = "config.txt";input = new FileInputStream( configFile );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.
[242 byte] By [ujavasuna] at [2007-10-3 4:10:33]
# 1
Hi,Store your configuration file under the directory of your web-apps folder. and give the complete pathegString filepath = "c:\\docroot\web-apps\txtfiles\config.txt";bye for nowsat
AnanSmritia at 2007-7-14 22:10:50 > top of Java-index,Java Essentials,Java Programming...
# 2
you are rightbut how can i provide the relative path?
ujavasuna at 2007-7-14 22:10:50 > top of Java-index,Java Essentials,Java Programming...
# 3
Hi,Please let me know your requirement.bye for nowsat
AnanSmritia at 2007-7-14 22:10:50 > top of Java-index,Java Essentials,Java Programming...
# 4
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 nowsat
AnanSmritia at 2007-7-14 22:10:50 > top of Java-index,Java Essentials,Java Programming...
# 5

> 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");

DrClapa at 2007-7-14 22:10:50 > top of Java-index,Java Essentials,Java Programming...
# 6

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

"

ujavasuna at 2007-7-14 22:10:50 > top of Java-index,Java Essentials,Java Programming...
# 7

> 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.

DrClapa at 2007-7-14 22:10:50 > top of Java-index,Java Essentials,Java Programming...
# 8

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("");

.

.

.

.

}

Mr.Rama at 2007-7-14 22:10:50 > top of Java-index,Java Essentials,Java Programming...