16进制转字符串

  1. private static String hexStringToString(String s) {
  2. if (s == null || s.equals("")) {
  3. return null;
  4. }
  5. s = s.replace(" ", "");
  6. s = s.replace("0x", "");
  7. byte[] baKeyword = new byte[s.length() / 2];
  8. for (int i = 0; i < baKeyword.length; i++) {
  9. baKeyword[i] = (byte) (0xff & Integer.parseInt(s.substring(i * 2, i * 2 + 2), 16));
  10. }
  11. return new String(baKeyword, StandardCharsets.UTF_8);
  12. }

文件复制

  1. File file = getFile(cfg);
  2. FileUtils.copyFile(file, cfg.getResponse().getOutputStream());
  3. int n;
  4. FileInputStream fis = new FileInputStream(file);
  5. byte[] buffer = new byte[4096];
  6. for (; -1 != (n = fis.read(buffer)); ) {
  7. cfg.getResponse().getOutputStream().write(buffer, 0, n);
  8. }
  9. file.deleteOnExit();

根据多个字符分割字符串

  1. String s = "123,45;iops,123;,234";
  2. String[] arr = s.split("[,,;;]");
  3. for (String a : arr) {
  4. System.out.print(a + " %%");
  5. }