Converting byte array to String (Java)

前端 未结 7 1083
不知归路
不知归路 2020-11-28 06:29

I\'m writing a web application in Google app Engine. It allows people to basically edit html code that gets stored as an .html file in the blobstore.

I\

7条回答
  •  青春惊慌失措
    2020-11-28 07:10

    public class Main {
    
        /**
         * Example method for converting a byte to a String.
         */
        public void convertByteToString() {
    
            byte b = 65;
    
            //Using the static toString method of the Byte class
            System.out.println(Byte.toString(b));
    
            //Using simple concatenation with an empty String
            System.out.println(b + "");
    
            //Creating a byte array and passing it to the String constructor
            System.out.println(new String(new byte[] {b}));
    
        }
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            new Main().convertByteToString();
        }
    }
    

    Output

    65
    65
    A
    

提交回复
热议问题