PrintWriter's println & print method .. Weird !!
Hi..
I have stumbled across a strange behaviour..
when i am trying to write to a file using the printwriter's println method, it is failing with a NullPointer exception. The same if done using a print() method of the same class, runs fine..
On some debugging i found out that on initialisation of the Printwriter class, the lineSeperator field of the class is set to null and when this String is being writen to the file, the Null Pointer arises..
The lineSeperator is being found out by using this piece of code...
//Code
lineSeparator = (String) java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("line.separator"));
//End Code
this is giving me a null.. and am left wondering..
Can any one of you share any light on this...
The following is the code in which i am getting Null pointer..
-----------------------
//--> s2 is a String that I want to store in IODemo.txt
BufferedReader in4 = new BufferedReader(new StringReader(s2));
PrintWriter out1 = new PrintWriter(new BufferedWriter(
new FileWriter("IODemo.txt")),true);
int lineCount = 1;
while ((s = in4.readLine()) != null){
out1.println(lineCount++ + ": " + s); //This gives Null Pointer Exception
//out1.println(lineCount++ + ": " + s); //This runs fine.. !!!
}
------------------------
TIA !
Rgds,
Vaibhav