2012-08-22 4 views
0

나는 HTTP 연결을 유지해야하고 이미지 문서에 쓰여진 텍스트를 얻기 위해 서버에 저장된 이미지의 이름으로 BB 앱을 만들고있다.블랙 베리에서 읽을 수있는 문자열 형식으로 바이트를 변환 하시겠습니까?

RTF 형식의 응답을 받고 있습니다. Chrome 브라우저를 열어 서버에 직접 접속하면 RTF 파일이 다운로드됩니다. 는 지금은 그 programetically 수행해야

1) Either convert the bytes which are coming in response in a simple string format so that I can read that. 

또는

2) Download the file as its happening on the browser manually so that by reading that file I read the information written in the document. 

내가 어떤 URL을 쳐서 서버에서 데이터를 읽을 수있는 방법을 나에게 제안 해주십시오?

현재이 코드 함께 일하고 :

try { 
    byte []b = send("new_image.JPG"); 
    String s = new String(b, "UTF-8"); 
    System.out.println(s); 
    } catch (Exception e) { 
    e.printStackTrace(); 
    } 

public byte[] send(String Imagename) throws Exception 
    { 
     HttpConnection hc = null; 
     String imageName = "BasicExp_1345619462234.jpg"; 
      InputStream is = null; 
      ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
      byte[] res = null; 

     try 
     { 
     hc = (HttpConnection) Connector.open("http://webservice.tvdevphp.com/basisexpdemo/webservices/ocr.php?imgname="+imageName); 
      hc.setRequestProperty("Content-Type", "multipart/form-data;"); 
     hc.setRequestMethod(HttpConnection.GET); 
      int ch; 
     StringBuffer sb= new StringBuffer(); 
     is = hc.openInputStream(); 
      while ((ch = is.read()) != -1) 
      { 
      bos.write(ch); 
      sb.append(ch); 
      } 
     System.out.println(sb.toString()); 
     res = bos.toByteArray(); 
     } 
     catch(Exception e){ 
      e.printStackTrace(); 
     } 
     finally 
     { 
      try 
      { 
       if(bos != null) 
        bos.close(); 

       if(is != null) 
        is.close(); 

       if(hc != null) 
        hc.close(); 
      } 
      catch(Exception e2) 
      { 
       e2.printStackTrace(); 
      } 
     } 
     return res; 
    } 

응답은 같다 : rtf1 \ ANSI \ ansicpg1252 \ UC1 \ deflang1033 \ adeflang1033 \

{........ ...

데이터를 읽을 수는 있지만 형식이 지정되지 않았으므로 프로그래밍 방식으로 읽을 수 있습니다.

답변

0

나는이 작업을 수행했다 .... 실제로 실수는 서버 측에서 발생했다. OCR을 수행 할 때 형식 매개 변수가 이유가 정정되지 않았습니다.

+0

질문에 답변하는 경우 ** 수락 **하십시오. 그래도 도움이 필요하지 않습니다. 감사! – Nate

관련 문제