本文实例讲述了Java使用utf8格式保存文本文件的方法。分享给大家供大家参考,具体如下:
FileOutputStream fos = null; OutputStreamWriter writer = null; try { File file = new File(filepath); fos = new FileOutputStream(file); writer = new OutputStreamWriter(fos,"utf-8"); writer.write(makeLanguageRes(resource)); } catch (Exception e) { CheckXmlUtil.addErrorMsg(CheckXmlUtil.TEXT_FOMART_ERROR, CheckXmlUtil.SAVE_XML_FIALL, e); return null; } finally { try { if(fos != null){ fos.close(); } } catch (IOException e1) { CheckXmlUtil.addErrorMsg(CheckXmlUtil.TEXT_FOMART_ERROR, CheckXmlUtil.SAVE_XML_FIALL, e1); } if (writer != null) { try { writer.close(); } catch (IOException e) { CheckXmlUtil.addErrorMsg(CheckXmlUtil.TEXT_FOMART_ERROR, CheckXmlUtil.SAVE_XML_FIALL, e); } } }
希望本文所述对大家java程序设计有所帮助。