Problems writing to a CSV file with null values

I need to be able to find a way of filling a null with a blank. The

out.write (datarecord.get ("token")+ "t");

does not work, as some of the field are sometimes missing on the site.

I read a suggestion here about using:

out.write(nullToEmptyString(session.getVariable("make")) + "," );

instead, but I keep getting an error message that I can't understand, (newbie to all this)
An error occurred while processing the script: WriteDataToAFile
The error message was: class bsh.ParseException (line 31): -- Encountered "" at line 31, column 2.

here is my script for the file - I'd be grateful for any help, (it works OK if I leave out the fields that are sometimes missing, but I want the data when it is there.)

String nullToEmptyString( String value )
{
if( value==null )
{
return "";
}

return value;

FileWriter out = null;

try
{
session.log( "Writing data to a file." );

// Open up the file to be appended to.
out = new FileWriter( "truckauctions.txt", true );

// Write out the data to the file.

out.write(nullToEmptyString(session.getVariable("make")) + "," );
out.write(nullToEmptyString(session.getVariable("model")) );
out.write("\n" );

// Close up the file.
out.close();
}
catch( Exception e )
{
session.log( "An error occurred while writing the data to a file: " + e.getMessage() );
}

Thanks for your help in advance!

Jason

nullToEmptyString

Your nullToEmptyString function is never closed. Put a closing curly brace after the line

return value;
before
FileWriter out = null;

See if that helps.