• Post Reply Bookmark Topic Watch Topic
  • New Topic

Writing errors to file (HELP)  RSS feed

 
kam mad
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I am student in a work placement and need to have my code running asap to impress my manager. (please help, i beg you)
Anyway, my code is below and what i need it to do now is to write all erros to the file calles "resultFile". At the lower end you will see write methods that are supposed to write the erros to the above file but when i search my c: drive i do not find the file. Can anyone help me in this? i would greatly appreeciate help
thanks

* CODE tags added by Jason
[ August 27, 2003: Message edited by: jason adam ]
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I take it you are running the application from somewhere on C:\?
Second, what messages do you see displayed to the console?
Third, I would use a PrintWriter instead of a FileWriter. PrintWriters give you methods like print() and println() that allow you to write text data to a file line by line. The way you have it, all that stuff you are writing is going to be crammed together unless you stick in "\n" to separate each line.
 
kam mad
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply
the prog is being run in dos, directory path: C:\Dev\Projects\XML\Code\EntityTest, the console displays that the validation/transformation and then validation again is complete. if there are any errors these are shown here aswell, do you any examples of solutions to this?
i also have to program the code so it prompts the user about any errors that exist in the validation/transformation? hope to hear from you soon.

kam
 
kam mad
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
updated the writer, still cannot find a file:
private void printInfo(SAXParseException e )
{
// takes errors and writes them to a file
try
{//a new FileDescriptor describing open file created

PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("resultFile", true)));
out.println("Public ID: "+e.getPublicId());
out.println(" System ID: "+e.getSystemId());
out.println(" Line number: "+e.getLineNumber());
out.println(" Column number: "+e.getColumnNumber());
out.println(" Message: "+e.getMessage());
out.close();
}
catch (Exception ex)
{
System.out.println("error in writing file");
}
}
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the issue is just finding the file, try this: Make a new File() with your filename, and display its absolute path. That should tell you where Java is putting stuff. I find myself doing this in different IDEs because I don't know what they give Java for the "current" directory. Or can you hardcode the full path for your file?
If the issue is maybe nothing is being written, I'm not helping much.
[ August 28, 2003: Message edited by: Stan James ]
 
kam mad
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks stand, very much appreciated, any one else have any suggestions?
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't forget to flush the writer.
Try putting a simple System.out.println( "In printInfo method" ); statement in the printInfo() method (duh). I'm curious if it is even hitting this method, even when an error occurs.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!