Topic: 急求:怎样将 String形式 转为 Byte 形式 |
Print this page |
1.急求:怎样将 String形式 转为 Byte 形式 | Copy to clipboard |
Posted by: beauty09 Posted on: 2009-10-11 13:56 public class Main { public static void main(String[] args) { // TODO code application logic here String text = "Code\tProject name\titem amount\tCost\n1\tAC peanut375GM\t\t2\t" + "$3.00\n2\tSweet photatoes\t\t1kg\t$2.48\nTotal cost\t\t\t\t\t$8.48\n"; System.out.print(text); byte[] b1 = text.getBytes(); System.out.println(b1); } 答案: Code Project name item amount Cost 1 AC peanut375GM 2 $3.00 2 Sweet photatoes 1kg $2.48 Total cost $8.48 [B@126804e 问题是 byte of text = [B@126804e 不是个数字啊。 计算机读写是不是有问题。 [B@126804e 是什么东西啊? 感激不尽! |
2.Re:急求:怎样将 String形式 转为 Byte 形式 [Re: beauty09] | Copy to clipboard |
Posted by: fneg Posted on: 2009-10-15 09:32 1. public static void main(String[] args) { 2. // TODO code application logic here 3. String text = "Code\tProject name\titem amount\tCost\n1 \ tAC peanut375GM\t\t2\t" + "$3.00\n2\tSweet photatoes\t\t1kg\t$2.48\nTotal cost\t\t\t\t\t$8.48\n"; 4. System.out.print(text); 5. byte[] b1 = text.getBytes(); 6. System.out.println(b1); 7. } 8. Code Project name item amount Cost 9. 1 AC peanut375GM 2 $3.00 10. 2 Sweet photatoes 1kg $2.48 11. Total cost $8.48 12. [B@126804e 对于输出的解释:第8行到11行的输出对应的是程序的第4行!(这个你应该看的懂吧?)第12行对应的是程序第6行!这个输出@前面的是你的对象名,@后面的是这个对象的hascode的十六进制的值。你可以试着再添加如下语句: System.out.println(Integer.toHexString(b1.hascode())); 这个语句输出就是@后面的值!如果还有问题,发E-mail给我 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |