【问题标题】:How to read binary file place in server?如何读取服务器中的二进制文件?
【发布时间】:2013-08-20 13:39:25
【问题描述】:

我想读取放置在服务器中的二进制文件。我想要的是数据应该放在字节数组中。

以下是我的一段代码:

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();

但我没有得到正确的结果

【问题讨论】:

  • 你得到了什么?有什么例外吗?
  • 你的方法不是很快也不是太复杂。更好地读取缓冲区中的字节并将块放入 ByteArrayOutputStream
  • 我没有得到任何异常,但我没有得到正确的结果

标签: android bytearray bytebuffer


【解决方案1】:

试试这个:(它读取图像,但可以修改为读取通用二进制文件)

        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(); 

【讨论】:

  • 这里的bm是什么
猜你喜欢
  • 2019-04-10
  • 1970-01-01
  • 1970-01-01
  • 2011-01-26
  • 1970-01-01
  • 1970-01-01
  • 2013-01-08
  • 1970-01-01
相关资源
最近更新 更多