2010-04-23 7 views
2

) 이러한 몇 줄의 코드는 "java.lang.ArrayIndexOutOfBoundsException"예외를 제공하고 있습니다. 누군가가 살펴보고 이유를 지적 할 수 있습니까? 예외가 발생했습니다. 제 arraycopy() 호출) : I가 새로운 바이트 쓰면"java.lang.ArrayIndexOutOfBoundsException"with System.arraycopy (

byte [] newContentBytes = EntityUtils.toByteArray((serverResponse.getEntity())); 
    newContent = new String(newContentBytes); 
    System.out.println(newContent); 
    byte [] headerBytes = headers.getBytes(); 
    byte[] res = new byte[newContentBytes.length + headerBytes.length]; 
    //headerBytes. 
    System.arraycopy(headerBytes, 0, res, 0, headerBytes.length); 
    System.out.println("length: " + newContentBytes.length); 
    System.arraycopy(newContentBytes, 0, res, newContentBytes.length , newContentBytes.length); 

문제는, 예를 들면, 입술의 크기 할당에 [newContentBytes.length는 + headerBytes.length + 2,000 대신 예외 정도로 발생하지 않는다 정확한 크기는 무엇입니까?

답변

3

글을 쓸 색인이 잘못되었습니다. 사용해보기 :

System.arraycopy(newContentBytes, 0, res, headerBytes.length , newContentBytes.length); 
관련 문제