2011-08-25 37 views
3

我需要在字符串生成器中追加字节00000000的字节。 我需要把它放到字符串数组中,然后再读一遍。 例如:什么是等于00000000字节的字符?

StringBuilder sBfNumRow = new StringBuilder(); 
sBfNumRow.append(""); //add char that 00000000 in byte 
stObj [c] = sBfNumRow.toString(); // put into String array 
stObj [c] .getBytes // read it again later. 

有人可以帮我做到这一点吗?

+1

你的意思是\ 0? –

+3

使用sBfNumRow.append('\ u0000'); –

+0

00000000字节 –

回答

0

A char and int可以彼此铸造以便使用该技术。

举例说明。

int a = 0; 
char zero = a; 

或者使用直接0无0

char zero = 0; 

并在代码中的那样。

BfNumRow.append((char) 0); //add char that 00000000 in byte 

编辑:新的答案提供思路,以提高我的回答

1

这将是

BfNumRow.append((char) 0); 

如果你想专门使用char类型。这

BfNumRow.append(0); 

将使用StringBuilder.append(int)

相关问题