首先建立自己的console控制台网上有很多这种例子,javaEye上的一位朋友写的很详细这里贴出来:
http://lengbingteng-163-com.iteye.com/blog/1116984
还有一篇也不错,很实际:
Eclipse插件开发之建立Console视图并在其中显示自定义信息
这篇文章连接子:http://www.blogjava.net/hengheng123456789/archive/2006/11/29/84343.html
虽然能够建立一个自定义的console,可我的问题并不在这里,而是将从后台获取的字符串在控制台MessageConsole中输出的时候,显示中文是乱码的问题;困扰了半天,首先来看MessageConsole:
org.eclipse.ui.console.
MessageConsole.MessageConsole(
String name,
String consoleType,
ImageDescriptor imageDescriptor,
String encoding, boolean autoLifecycle)
Constructs a message console with the given name, type, image, encoding, and lifecycle specification.
-
Parameters:
- name the name to display for this console
-
consoleType console type identifier or
null
-
imageDescriptor console image descriptor or
null
-
encoding the encoding that should be used to render the text, or
null
if the system default encoding should be used - autoLifecycle whether lifecycle methods should be called automatically when added and removed from the console manager
-
- 开始认为这里的encoding指定为utf-8后,应该就可以正常显示中文了,但还是显示中文lua那么,最后发现把与该MessageConsole绑定的MessageConsoleStream的encoding指定为utf-8就好了;原来MessageConsole的输出字符串来自于MessageConsoleStream.println(“要输出的字符串”);
- 所以设定MessageConsoleStream.setEncoding("utf-8");之后就可以正常显示了;
-
- 编码问题非常常见,不过看来只要能够弄明白数据的传输过程中到底是怎么样进行的,再详细检查数据传递过程中的编码设置,那么应该就可以搞定了!
-
- 2011-12-02
-
-
-
-