Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我搜索了很多,我似乎找不到任何与在 Java 中将字符串转换为固定长度字节相关的内容,我不知道这是否可能,因为我们已经得到了编码。
String word = "asdsda"; byte[] bytes = Java.Convert(word, 20);
正如上面的示例所示,Java 中有没有办法将字符串转换为固定的正字节值?
String word = "asdsda"; byte[] bytes = word.getBytes("UTF-8");
会给你6个字节。
字符编码是有规则的,字符到字节的转换,必须在某些编码规则的约束下,否则毫无意义