0
我正在開發一個BB應用程序,我需要維護一個HTTP連接和存儲在服務器上的圖像名稱,以獲取寫入該圖像文檔的文本。將黑莓中的字節轉換爲可讀的字符串格式?
我得到了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 ........ ...........
我可以讀取數據,但它沒有格式化,所以我也可以讀取它的編程。
如果你回答自己的問題,也請**接受**,所以我們知道你不需要幫助。謝謝! – Nate