Want to write Unicode to a file? Say no more:
public void write(String stuff, String toFilename)
throws IOException
{
FileOutputStream fos = null;
OutputStreamWriter osw = null;
BufferedWriter theFile = null;
try
{
fos = new FileOutputStream(toFilename);
osw = new OutputStreamWriter(fos, "utf-8");
theFile = new BufferedWriter(osw);
theFile.write(stuff);
theFile.flush();
}
finally
{
try
{
if (fos != null)
{
fos.close();
}
if (osw != null)
{
osw.close();
}
if (theFile != null)
{
theFile.close();
}
}
catch (IOException ignored)
{
log4jLogger.error(ignored);
}
}
}
No comments:
Post a Comment