2013-08-20 68 views
0

我想讀取放置在服務器中的二進制文件。我想要的是數據應該放在bytearray中。如何讀取服務器中的二進制文件位置?

以下是我的一段代碼:

BufferedReader in = new BufferedReader(new InputStreamReader(uurl.openStream())); 

String str; 
while ((str = in.readLine()) != null) { 
    text_file=text_file+str; 
    text_file=text_file+"\n"; 
} 
m_byteVertexBuffer=text_file.getBytes(); 

,但我沒有得到正確的結果

+0

是/正在獲取?有什麼異常? –

+0

你的方法不是很快,也很複雜。更好地讀取緩衝區中的字節並將塊放入ByteArrayOutputStream –

+0

我沒有發現任何異常,但我沒有得到正確的結果 –

回答

0

試試這個:(讀取的圖像,但可以修改爲通用二進制文件)

 aURL = new URL(imageUrl); 
     URLConnection conn = aURL.openConnection(); 
     InputStream is = new BufferedInputStream(conn.getInputStream()); 
     BitmapFactory.Options options = new BitmapFactory.Options(); 
     is = new BufferedInputStream(conn.getInputStream()); 
     bm = BitmapFactory.decodeStream(is, null, options); 
     is.close(); 
+0

在這種情況下,bm是什麼 –

+0

bm只是一個位圖 – Martin