Java 的 OutputStreamWriter 不会写入 utf8 bom 标记的.
下面给一个写入UTF8 BOM标记的例子:
public static void saveFile(String file, String data, boolean append) throws IOException {
BufferedWriter bw = null;
OutputStreamWriter osw = null;
File f = new File(file);
FileOutputStream fos = new FileOutputStream(f, append);
try {
// write UTF8 BOM mark if file is empty
if (f.length() < 1) {
final byte[] bom = new byte[] { (byte)0xEF, (byte)0xBB, (byte)0xBF };
fos.write(bom);
}
osw = new OutputStreamWriter(fos, "UTF-8");
bw = new BufferedWriter(osw);
if (data != null) bw.write(data);
} catch (IOException ex) {
throw ex;
} finally {
try { bw.close(); fos.close(); } catch (Exception ex) { }
}
}
2009年1月21日星期三
BOM标记UTF8文件的例子
2009年1月15日星期四
给RCP增加快捷键
1:添加org.eclipse.ui.contexts扩展点,用于限定快捷键激活区域
如
《extension
point="org.eclipse.ui.contexts">
《context
id="org.nightatriver.rcp.view.ArithmeticTreeView"
name="ArithmeticTreeView">
《/context>
《/extension>
2.添加org.eclipse.ui.bindings扩展点,用于关联快捷键、调用功能、激活区域。
如:
《extension
point="org.eclipse.ui.bindings">
《key
commandId="org.nightatriver.rcp.action.ActivateAction"
contextId="org.nightatriver.rcp.view.ArithmeticTreeView"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="CTRL+SHIFT+A">
《/key>
《key
commandId="org.nightatriver.rcp.action.ImportXlsAction"
contextId="org.eclipse.ui.contexts.window"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="CTRL+I">
《/key>
《/extension>
3.添加org.eclipse.ui.commands扩展点
如:
《extension
point="org.eclipse.ui.commands">
《category
name="actions"
id="org.nightatriver.rcp.action">
《/category>
《command
id="org.nightatriver.rcp.action.ActivateAction"
name="Activate Monitor">
《/command>
《command
id="org.nightatriver.rcp.action.ImportXlsAction"
name="Import Action">
《/command>
《/extension>
如
《extension
point="org.eclipse.ui.contexts">
《context
id="org.nightatriver.rcp.view.ArithmeticTreeView"
name="ArithmeticTreeView">
《/context>
《/extension>
2.添加org.eclipse.ui.bindings扩展点,用于关联快捷键、调用功能、激活区域。
如:
《extension
point="org.eclipse.ui.bindings">
《key
commandId="org.nightatriver.rcp.action.ActivateAction"
contextId="org.nightatriver.rcp.view.ArithmeticTreeView"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="CTRL+SHIFT+A">
《/key>
《key
commandId="org.nightatriver.rcp.action.ImportXlsAction"
contextId="org.eclipse.ui.contexts.window"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="CTRL+I">
《/key>
《/extension>
3.添加org.eclipse.ui.commands扩展点
如:
《extension
point="org.eclipse.ui.commands">
《category
name="actions"
id="org.nightatriver.rcp.action">
《/category>
《command
id="org.nightatriver.rcp.action.ActivateAction"
name="Activate Monitor">
《/command>
《command
id="org.nightatriver.rcp.action.ImportXlsAction"
name="Import Action">
《/command>
《/extension>
订阅:
博文 (Atom)