网络获取到展现速度较慢
定位:在HttpURLConnection.getInputStream()之后的处理
解决:使用BufferedReader替代BufferedInputStream获取时间从100ms降低到3ms,具体代码修改如下:
1
2
3
4
5
|
HttpURLConnection
con
=
(
HttpURLConnection
)
url
.
openConnection
(
)
;
InputStream
input
=
con
.
getInputStream
(
)
;
while
(
input
.
read
(
buffer
,
0
,
1024
)
!=
-
1
)
{
}
|
改为
1
2
3
4
5
6
|
HttpURLConnection
con
=
(
HttpURLConnection
)
url
.
openConnection
(
)
;
BufferedReader
input
=
new
BufferedReader
(
new
InputStreamReader
(
con
.
getInputStream
(
)
)
)
;
String
s
;
while
(
(
s
=
input
.
readLine
(
)
)
!=
null
)
{
}
|