首页javabyteJava Data Type - 如何将字符串转换为字节

Java Data Type - 如何将字符串转换为字节

我们想知道如何将字符串转换为字节。
public class Main {
  public static void main(String[] args) {
    String s = "65";

    byte b = Byte.valueOf(s);

    System.out.println(b);

    // Causes a NumberFormatException since the value is out of range
    System.out.println(Byte.valueOf("129"));
  }
}