⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 characode.java

📁 java树型字典的建立,是中文分词 检索的基础
💻 JAVA
字号:
package ECDictionaryUtil;

public class CharaCode {

	/**
	 * @param args
	 */
 public int getCharaCode(String chara)throws Exception
	 { byte[] bytes = chara.getBytes("gbk");
     if(bytes == null || bytes.length > 2 || bytes.length <= 0|| bytes.length == 1)
 { throw new Exception("不是一个有效的汉字!"); }
     if(bytes.length == 2){ //汉字
      int hByte,lByte;//汉字的高字节和低字节
      if (bytes[0]<0)
 { 
   hByte = 256 + bytes[0];
 }
 else{
	 //hByte = bytes[0]; 
	 throw new Exception("不是一个有效的汉字!");
	 }
 if (bytes[1]<0)
 { 
   lByte= 256 + bytes[1];
 }
 else{
	 //lByte = bytes[1]; 
	 throw new Exception("不是一个有效的汉字!");
	 }
  
   int iHanzi = (256 * hByte + lByte);
   return iHanzi;
     }
   throw new Exception("不是一个有效的汉字!");
   }
	public static void main(String[] args) {
	   String cha="华";
		try{
		System.out.println(new CharaCode().getCharaCode(cha));
		
	}catch(Exception ee){
		System.out.println(ee.getMessage());
	}

	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -