标签:try 图片 img UI write exce build tao finally
要求:
汉字:GBK内码
西文:ASCII码
间隔符:
/** * 字段间隔符 */ private static final String FIELD_INTERVAL = new String(new byte[]{0x01}); /** * 行间隔符 */ private static final String LINE_INTERVAL = new String(new byte[] {0x0A});
转码:(对西文进行转ASCII码)
private void appendWithAscii(StringBuilder builder, Object... value) { for (Object object : value) { if (object != null) { builder.append(getAscii(String.valueOf(object))); } builder.append(FIELD_INTERVAL); } } private String getAscii(String input) { byte[] asciiByte = input.getBytes(Charsets.US_ASCII); return new String(asciiByte); }
以GBK方式通过二进制形式写入文件:
/** * 以二进制方式写入 * @param fileName * @param content * @param encoding * @return */ public static boolean writeFileBinary (String fileName, String content, String encoding) { boolean flag = false; DataOutputStream out = null; try { out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(fileName))); byte[] contentByte = content.getBytes(encoding); out.write(contentByte); flag = true; } catch (IOException e) { } finally { if (out != null) { try { out.close(); } catch (IOException e) { } } } return flag; }
文件二进制查看:工具(Binary Viewer)
其中 01 为 0x01,对应上面的 字段间隔符 (域间隔符)
0A为0x0A,对应上面的 行间隔符
此内容谨记录工作中所遇之事,深入了解待后续更新.....
未完待续....
标签:try 图片 img UI write exce build tao finally
原文地址:https://www.cnblogs.com/binbang/p/8992177.html