eclipse插件开发之控制台输出乱码问题

本文介绍了在Eclipse中解决中文乱码问题的方法。通过设置MessageConsoleStream的编码为utf-8,可以确保从后台获取的字符串在控制台正确显示中文。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先建立自己的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




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值