• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java code File and FileWriter

 
Sana Ali
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I am using DOM to make an xml tree and writing it to a file. The code involves use of java.

I have declared the fileName of the file:

String fileName = "/tmp/memberFile";

to save it to the file i have done the following:

File membersXMLFile = new File(fileName);
FileWriter writer;

if (!(membersXMLFile.exists()))
{
writer = new FileWriter(membersXMLFile);
}
else //file does exist
{
writer = new FileWriter(membersXMLFile, true);
}


if file does not exist FileWriter writes to file. else if it does exist, file writer writes to the file by appended to the file.

However, i am still getting a TOMCAT Error. As this is java code. I am confused on what is wrong with my code.

Please Help
Sana
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should be get path of current directory/floder in server at runtime.
 
Sana Ali
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but im told to set it to "/tmp/fileName.xml"

as TOMCAT server runs there, other wise the jsp file cannot be executed.

Anyway, my Q was about my java code...does it even make sense?
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, i'm sorry, i'm wrong ::

you should get absolute path of current directory Before read/create your files...
[ October 15, 2004: Message edited by: somkiat puisungnoen ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You haven't told us what error you're getting. If the error page doesn't include a stack trace, have you looked in catalina.out, and theother log files, for stack traces? Let us know what the actual error is, and maybe we can help. Otherwise, we're just fumbling around here -- there's nothing wrong with the code intrinsically, it's just a question of whether it does what you want it to do.

Note that appending to an existing XML file is just going to give you a broken XML file, by the way.
 
Sana Ali
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
error is:

type Exception report

message Internal Server Error

description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.

exception
javax.servlet.ServletException
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:471)


javax.servlet.ServletException
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:471)
at org.apache.jsp.memberdisplayWithDom$jsp._jspService(memberdisplayWithDom$jsp.java:542)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:201)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:381)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473)


root cause

java.lang.OutOfMemoryError
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is error in process compile jsp to SErvlet class of Jasper.

And OutOfMemoryError is occured from
- infinity loop.
- Server memory/heap size not enough.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic