You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

StringUtils.java 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package com.mirfalahtech.xprinter;
  2. import java.io.UnsupportedEncodingException;
  3. /**
  4. * Created by kylin on 2017/4/6.
  5. */
  6. public class StringUtils {
  7. /**
  8. * string to byte[]
  9. * */
  10. public static byte[] strTobytes(String str){
  11. byte[] b=null,data=null;
  12. try {
  13. b = str.getBytes("utf-8");
  14. data=new String(b,"utf-8").getBytes("gbk");
  15. } catch (UnsupportedEncodingException e) {
  16. // TODO Auto-generated catch block
  17. e.printStackTrace();
  18. }
  19. return data;
  20. }
  21. /**
  22. * byte[] merger
  23. * */
  24. public static byte[] byteMerger(byte[] byte_1, byte[] byte_2){
  25. byte[] byte_3 = new byte[byte_1.length+byte_2.length];
  26. System.arraycopy(byte_1, 0, byte_3, 0, byte_1.length);
  27. System.arraycopy(byte_2, 0, byte_3, byte_1.length, byte_2.length);
  28. return byte_3;
  29. }
  30. public static byte[] strTobytes(String str ,String charset){
  31. byte[] b=null,data=null;
  32. try {
  33. b = str.getBytes("utf-8");
  34. data=new String(b,"utf-8").getBytes(charset);
  35. } catch (UnsupportedEncodingException e) {
  36. // TODO Auto-generated catch block
  37. e.printStackTrace();
  38. }
  39. return data;
  40. }
  41. }