「java获取所有字符集」java获取所有字符集的数据
本篇文章给大家谈谈java获取所有字符集,以及java获取所有字符集的数据对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、java 文件上传中如何获取上传文件的字符集编码
- 2、Java中如何查看字符串是什么字符集
- 3、java中如何取操作系统字符集
- 4、如何查找默认的字符集/编码在Java中
- 5、关于java查询数据库字符集的问题
java 文件上传中如何获取上传文件的字符集编码
看看这篇
还有这个
这个是jchardet的地址
也有人写了用getEncoding
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
public class FileCharset {
public static void main(String[] args) throws FileNotFoundException {
InputStreamReader isr = new InputStreamReader(new FileInputStream(
"Service02.asp"));
System.err.println(isr.getEncoding());
BufferedReader br = new BufferedReader(isr);
}
}
但是不起作用
getEncoding gives you the encoding the reader is using, not what the file is
using. The problem is that there isn't anything in the file that says what
encoding it is using. You can look at some byte patterns to try to
determine whether it's UTF-8, UTF-16BE, or whatever but there's no perfect
rule for it.
Java中如何查看字符串是什么字符集
判断java字符串的字符集有多种方法,我们一一讨论如下:
1、通过把未知编码字符串,用猜想的编码再解码,观察字符串是不是正确还原了。
原理:假如目标编码没有数组中的字符,那么编码会破坏,无法还原。
缺点:假如字符少,而正巧错误的猜想编码中有这种字节,就会出错。
如:new String("tested str".getBytes("enc"),"enc")
2、大多数时候,我们只要判断本地平台编码和utf8,utf8编码相当有规律,所以可以分析是否是utf8,否则使用本地编码。
原理:分析byte[]来判断规律。
缺点:有时,个别本地编码字节在utf8中也会出现,导致出错,需要分析。
如:判断是否utf-8代码:
public static boolean isValidUtf8(byte[] b,int aMaxCount){
int lLen=b.length,lCharCount=0;
for(int i=0;i
byte lByte=b[i++];//to fast operation, ++ now, ready for the following for(;;)
if(lByte=0) continue;//=0 is normal ascii
if(lByte(byte)0xc0 || lByte(byte)0xfd) return false;
int lCount=lByte(byte)0xfc?5:lByte(byte)0xf8?4
:lByte(byte)0xf0?3:lByte(byte)0xe0?2:1;
if(i+lCountlLen) return false;
for(int j=0;j=(byte)0xc0) return false;
}
return true;
java中如何取操作系统字符集
class Test
{
public static void main(String[] args)
{
Properties pps=System.getProperties();
pps.list(System.out);
System.out.println("--------------------以上为JVM的所有属性值-------------");
System.out.print("系统默认的字符集为:");
String name=System.getProperty("sun.jnu.encoding");
System.out.print(name);
}
}
如何查找默认的字符集/编码在Java中
1, Java代码直接设置
System.out.println(System.getProperty("file.encoding"));
或
System.out.println(Charset.defaultCharset());
2,eclipse里面选中工程-properties-Resource:text file encoding 改成你的原文件编码格式即可;
3,一般配置jdbc连接字符串的时候可以指定字符编码集,指定成和数据库的编码一致即可,这样用jdbc读出来的数据就是解码后的正常的数据。当然,不同的数据库产品具体看怎么办。
关于java查询数据库字符集的问题
1. JDBC连接串要有字符集设置
jdbc:sybase:Tds:192.168.3.11:5000/Wfis_db?charset=cp936
我项目中的写法:
Db.url=jdbc:sybase:Tds:angkor[服务器名或IP]:5000/angkor[数据库名]?charset=eucgb
2. 服务器配置成cp936
(3) 因为上面的列表中没有安装cp936,所以就安装cp936字符集
进入目录C:\sybase\charsets\cp936
运行命令 charset -Usa -Plongtop binary.srt cp936
运行完成后,系统就安装了cp936字符集
(4) 验证是否确实安装了cp936字符集
isql -Usa -Plongtop
use master
go
select id,name from syscharsets
go
id name
(5) 把系统的当前缺省字符集设置为cp936
sp_configure "default char",171
go
In changing the default sort order, you have also reconfigured SQL Server's
default character set.
Parameter Name Default Memory Used Config Value
Run Value Unit Type
------------------------------ ----------- ----------- ------------
----------- -------------------- ----------
default character set id 2 0 171
2 id static
(1 row affected)
Configuration option changed. Since the option is static, Adaptive Server must
be rebooted in order for the change to take effect.
Changing the value of 'default character set id' to '171' increases the amount
of memory ASE uses by 6 K.
(return status = 0)
(6) 重启Sybase服务,使更改生效
第一次重启,系统会对已经存在的数据进行转换,转换完成后自动停止服务,只要再次启动服务就可以了。
(7) 更改DB客户端的字符集
DBArtisan中要更改客户端的字符集为cp936才能连接cp936的服务器
通过菜单\Logfile\Options...打开对话框,选择Connection标签,
更改Client Character输入框的值为cp936。
数据库的charset修改为cp936时,使用isql按如下的方式
isql -Usa -Plongtop -Sdbserver -Jcp936
java获取所有字符集的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java获取所有字符集的数据、java获取所有字符集的信息别忘了在本站进行查找喔。