0

我有一个填充了字节的文本字段。当我调用 String s = textfield.getText(); 默认情况下,它是它返回的字节的字符串数据类型。我想获取文本字段中的实际字节作为数据类型字节。但如果我执行 s.getbyte,我会将字节转换为新字节。请谁能帮助我。

           //this gives me another bye than the one in the text field.
            String ss = new String(Textfield().getText().getBytes(), "UTF-8");

            //i want to get something like this
            byte [] b = Textfield().getText(); //without geting a new byte
            String ss = new String(Textfield().getText().getBytes(), "UTF-8");
4

1 回答 1

-1

只需调用String#getBytes()并始终String#intern()在构造函数后调用将新字符串填充到字符串池中。

byte [] b = Textfield().getText().getBytes();
String ss = new String(Textfield().getText().getBytes(), "UTF-8").intern();
于 2013-10-19T21:12:31.683 回答