I set up my output data stream with this code. It works without any errors indicated:
try
{
println( "Path: " + selection.getCanonicalPath() );
println( "ext: \""+ getFileExtension(selection.getCanonicalPath() ) + "\"" );
if( sDataFileExt. compareTo( getFileExtension( selection.getCanonicalPath() ) ) != 0 )
{ fDataFile = new File( selection.getCanonicalPath() + ".csv" );
}else
{ fDataFile = new File( selection.getCanonicalPath());
}
pwDataFileStream = new PrintWriter( fDataFile );
if( !fDataFile.isFile() )
{ sDataFileMsg = "Cannot create file: \"" + fDataFile.getName() + "\"";
pwDataFileStream.close();
}else if( !fDataFile.canWrite() )
{ sDataFileMsg = "Cannot write to file: \"" + fDataFile.getName() + "\"";
pwDataFileStream.close();
}else if( pwDataFileStream.checkError() )
{
sDataFileMsg = "Trouble creating output stream";
pwDataFileStream.close();
}
else
{ sDataFileMsg = fDataFile.getName();
println( sDataFileMsg );
fStartingDataFilePath = new File( selection.getCanonicalPath() );
ini.put( sIniSectFile, sIniKeyDataFilePath, fStartingDataFilePath.getCanonicalPath() );
ini.store();
}
}catch(Exception e)
{ System.err.println(e.getMessage());
}
Elsewhere in the code I attempt write data using the code below. The output to the console shows that the asc[] int array is valid. In the try-catch block, only the first attempt to use pwDataFileStream.println() works. The four below it cause pwDataFileStream.checkError() to return positive.
println (asc[0]," ",asc[1]," ",asc[2]," ",asc[3]); // Works, outputs to console.
try
{
pwDataFileStream.println( "Something" ); // Works
pwDataFileStream.println( asc[0] + "," + asc[1] + "," + asc[2] + "," + asc[3] ); // .checkError() true
pwDataFileStream.printf( "%X,%X,%X,%X%n", asc[0],asc[1],asc[2],asc[3]); // .checkError() true
pwDataFileStream.printf( "%x,%x,%x,%x%n", asc[0],asc[1],asc[2],asc[3]); // .checkError() true
pwDataFileStream.printf( "%d,%d,%d,%d%n",asc[0],asc[1],asc[2],asc[3]); // .checkError() true
if( pwDataFileStream.checkError() )
{ pwDataFileStream.close();
sDataFileMsg = "File stream post-error";
println( sDataFileMsg );
}
}catch( Exception e )
{ System.err.println(e.getMessage());
pwDataFileStream.flush();
pwDataFileStream.close();
}
I know that these methods do not throw errors. I nevertheless used the try-catch block in case I am wrong.
It looks to me like something is wrong in the format specifiers. What?