Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using the load and store methods of the Properties class in an HttpServlet

4 views
Skip to first unread message

Nathan Sokalski

unread,
Apr 25, 2003, 6:28:28 PM4/25/03
to
I am using the load and store methods of the Properties class in an
HttpServlet. Everything works fine until the servlet tries to call the store
method of the Properties class. My code used to call the load and store
methods appears as follows:

try
{
propFile=new File("names.txt");
synchronized(this)
{
if(propFile.exists())
myNames.load(new FileInputStream(propFile));
}
}

try
{
synchronized(this)
{
myNames.store(new FileOutputStream(propFile),"Previously Registered
Visitors");
}
}

The load method does not seem to be causing any problems, but when the store
method is called the html page locks up for a little while, and I then
recieve an error on the server saying the following:

java.io.FileNotFoundException: names.txt (Permission denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:176)
at java.io.FileOutputStream.<init>(FileOutputStream.java:131)
at Register.doGet(Register.java:118)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:499)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:588)
at
sun.servlet.http.HttpServerHandler.sendResponse(HttpServerHandler.java:165)
at
sun.servlet.http.HttpServerHandler.handleConnection(HttpServerHandler.java:1
21)
at sun.servlet.http.HttpServerHandler.run(HttpServerHandler.java:90)
at java.lang.Thread.run(Thread.java:536)
java.io.IOException: tried to write more than content length
at
sun.servlet.http.HttpOutputStream.check(HttpOutputStream.java:282)
at
sun.servlet.http.HttpOutputStream.write(HttpOutputStream.java:318)
at
sun.nio.cs.StreamEncoder$CharsetSE.writeBytes(StreamEncoder.java:334)
at
sun.nio.cs.StreamEncoder$CharsetSE.implFlushBuffer(StreamEncoder.java:403)
at
sun.nio.cs.StreamEncoder$CharsetSE.implFlush(StreamEncoder.java:407)
at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:150)
at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:213)
at java.io.PrintWriter.flush(PrintWriter.java:120)
at sun.servlet.http.HttpResponse.finish(HttpResponse.java:337)
at
sun.servlet.http.HttpServerHandler.handleConnection(HttpServerHandler.java:1
33)
at sun.servlet.http.HttpServerHandler.run(HttpServerHandler.java:90)
at java.lang.Thread.run(Thread.java:536)

If anyone could tell me what I am doing wrong with the store method, I would
appreciate it. Thank You.
--
Nathan Sokalski
njsok...@hotmail.com
http://studentwebs.kutztown.edu/soka0908/HomePage.html


Andy Flowers

unread,
Apr 26, 2003, 3:38:24 AM4/26/03
to
It may sound obvious, but have you checked the permissions of the names.txt
file ? Is it read-only ? The error says Permissions Denied so it is probably
useful to check the rights.

"Nathan Sokalski" <njsok...@hotmail.com> wrote in message
news:b8ccqo$8g3rb$1...@ID-191000.news.dfncis.de...

Nathan Sokalski

unread,
Apr 26, 2003, 6:02:39 PM4/26/03
to
I have checked the permissions, and it is not read-only. However, the only
reason I created the file to begin with is to see if it would help the
error. In case you did not notice, the load method is inside an if statement
asking whether the file exists, therefore, unless there is a problem with my
if statement, the load method would not have been getting called before I
manually added a file named names.txt. I recieve the same error regardless
as to whether or not I manually created the names.txt file.

"Andy Flowers" <andrew....@npspam.ntlworld.com> wrote in message
news:qIqqa.1482$ZS4....@newsfep4-glfd.server.ntli.net...

Andy Flowers

unread,
Apr 26, 2003, 6:58:08 PM4/26/03
to
Try this debug trick I've had to use on some servers in the past

Replace the .store command with propFile

System.out.println( propFile.getAbsolutePath());
System.out.println( propFile.getCanonicalPath());

to confirm that where you think the servlet engine is putting the file is
where it is being put.

Once you have this information it 'may' be a little better to debug.

Which servlet engine are you using and on which OS and which JDK ?

"Nathan Sokalski" <njsok...@hotmail.com> wrote in message

news:b8evm7$96gju$1...@ID-191000.news.dfncis.de...

nin...@yahoo.es

unread,
Apr 28, 2003, 4:54:50 AM4/28/03
to
Close the FileInputStream after load the properties
0 new messages