将String str=new String(buff);放到try...catch...内

解决方案 »

  1.   

    try()内的语句可能执行不到(如果发生exception),则buff未初始化,即未执行buff=new byte[size]
      

  2.   

    但是没有发生exception呀
    怎么也没初始化?
      

  3.   

    但是没有发生exception呀
    怎么也没初始化?
      

  4.   


    Long length;
    int size;
    try
    {
      byte[] buff;
      RandomAccessFile file=new RandomAccessFile(f,"r");
      length=new Long(file.length());
      size=length.intValue();
      buff=new byte[size];
      file.readFully(buff);
      String str=new String(buff);
      System.out.println(str);
    }
    catch(IOException ex)
    {
       System.out.println("I/O error: "+ex);
    }
      
      

  5.   

    那在try{}
    中定义德buff是全局变量吗?
      

  6.   

    改成byte[] buff=null;
    试试?
      

  7.   

    在编译的时候会自动判断的
    你认为没有exception
    可是在执行过程中说不定就有exception
    那么你的buff就没有得到初始化同意MicroDirt(微尘)的方法:byte[] buff = null
    或者你也可以把String str = new String(buff);一句放到try里面
      

  8.   

    : kellychen(陈慧琳) 
       byte[] buff;   
       try
      {
      
      
      

  9.   

    你在TRY内NEW的BUFF,只作用于TRY内.TRY外使用就会说你的buff没有初始化
      

  10.   

    : seal_kh() 
         同意同意