今天准备将SGIP用JAVA来写写。使用JBUILDER,测试WINXP/LINUX均通过,没有正式编码,只是测试了一下简单的发送接收 SOCKET。手机接收短信OK。 找了半天JAVA BCD编码资料,都是乱七八糟的,没有什么有用的东西,有个JAVA类库倒是提供STR2BCD,可是我又没有必要使用如此一个类库。因此还是自己写一下算了。比较弱智的写法。 public byte [] str2bcd(String str) { String s=str.toUpperCase(); int ii=str.length(); byte [] b=new byte[ii/2]; for(int i=0,j=0;i<ii;i++,j++) { int i1,i2; if(s.charAt(i) -'A'>=0) i1=s.charAt(i) -'A'+10; else i1=s.charAt(i) -'0'; if(s.charAt(i+1) -'A'>=0) i2 = s.charAt(i+1) - 'A' + 10; else i2 = s.charAt(i+1) - '0'; b[j]=(byte)(i1*0x10+i2); i=i+1; } return b; } public void printbytes(byte []b) { String str; for(int i=0;i<b.length;i++) { str= Integer.toHexString((int)(b[i]&0xff)); if(str.length()==1) str="0"+str; System.out.print(str); } }byte[] b; String strOut = null; if(strIn == null || (strIn.trim()).equals("")) return strIn; try{ b = strIn.getBytes("GBK"); strOut = new String(b,"ISO8859_1"); }catch(UnsupportedEncodingException e){ } return strOut; 比起C#来真是麻烦多了 http://www.shengfang.org/blog/p/vsnetbcdstring.php Jbuilder生成可执行文件 打包 To create an archive with the Archive Builder: Open the project you wish to deploy. Build the project to create the .class files, copy resources, and so on. Choose File|New and select the Archive page. Double-click the type of archive you want to run and complete the steps of the wizard. Right-click the archive node in the project pane and choose Make to create the archive. 最好选择 Creating executables with the Native Executable Builder archive executable jar 字体:大 中 小 |