this.fileN=Byte.parseByte(this.fileName);
编译没问题,就是在运行的时候会抛出下面的错误,还望高手指点啊!!
Exception in thread "main" java.lang.NumberFormatException: For input string: "c
cgif"
        at java.lang.NumberFormatException.forInputString(Unknown Source)
        at java.lang.Integer.parseInt(Unknown Source)
        at java.lang.Byte.parseByte(Unknown Source)
        at java.lang.Byte.parseByte(Unknown Source)
        at ClientTrans.<init>(ClientTrans.java:16)
        at ClientTrans.main(ClientTrans.java:73)

解决方案 »

  1.   

    this.fileN=Byte.parseByte("12");
    The characters in the string must all be decimal digits
    必须要是十进制数字,而且范围不能超过 byte范围
      

  2.   

    this.fileN = this.fileName.getBytes() 这样可以返回一个byte[] 数组
      

  3.   

    呵呵,看看这里的解释:
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Byte.htmlparseByte
    public static byte parseByte(String s)
                          throws NumberFormatExceptionParses the string argument as a signed decimal byte. The characters in the string must all be decimal digits, except that the first character may be an ASCII minus sign '-' ('\u002D') to indicate a negative value. The resulting byte value is returned, exactly as if the argument and the radix 10 were given as arguments to the parseByte(java.lang.String, int) method. Parameters:
    s - a String containing the byte representation to be parsed 
    Returns:
    the byte value represented by the argument in decimal 
    Throws: 
    NumberFormatException - if the the string does not contain a parsable byte.这里的参数s必须是个符号的十进制数才能转换。
    不过你可以用以下的几种方法:
    1:getBytes()
    public class Test { /**
     * @param args
     */
    public static void main(String[] args) {
    String s = "~sfsadfa";
          Byte[] c = s.getBytes();
          int len = c.length;
          System.out.println("len : "+ len);
          for(int loop = 0; loop < len; loop++){
          System.out.println("c["+loop+"] = "+c[loop]);
          }
    }}2:valueOf()
    import java.lang.Byte;public class Test { /**
     * @param args
     */
    public static void main(String[] args) {
    String s = "~sfsadfa";
          Byte c = Byte.valueOf(s);
    //      int len = c.length;
    //      System.out.println("len : "+ len);
    //      for(int loop = 0; loop < len; loop++){
    //      System.out.println("c["+loop+"] = "+c[loop]);
    //      }
    }}