嗨,下面的代码适用于这种情况。
HttpURLConnection connection = (HttpURLConnection) (new URL("http://" + account + ".table.core.windows.net/"+urlPath)).openConnection();
signRequestSK(connection, account, key);
connection.connect();
ByteArrayOutputStream sink = new ByteArrayOutputStream();
copy(connection.getInputStream(), sink, 3000);
byte[] downloadedFile = sink.toByteArray();
String str = new String(downloadedFile, "UTF8");
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Title");
alert.setMessage(str);
alert.show();
复制功能
public static void copy(InputStream in, OutputStream out , int bufferSize)
throws IOException
{
// Read bytes and write to destination until eof
byte[] buf = new byte[bufferSize];
int len = 0;
while ((len = in.read(buf)) >= 0)
{
out.write(buf, 0, len);
}
}