我從以下網絡代碼獲得BufferedReader
。從BufferedReader獲得字符串的更好的方法
URL url = new URL(request);
HttpURLConnection httpUrlConnection = (HttpURLConnection)url.openConnection();
InputStream inputStream = httpUrlConnection.getInputStream();
bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
- 我想知道,哪種方式提供更高的效率,執行速度的期限?
1024尺寸是Android的不錯選擇?或者,有沒有我可以使用的任何系統常量值?
int charRead = 0; char[] buffer = new char[1024]; StringBuffer stringBuffer = new StringBuffer(); while ((charRead = bufferedReader.read(buffer)) > 0) { stringBuffer.append(buffer, 0, charRead); }
String line = "";
StringBuffer stringBuffer = new StringBuffer();
while ((line = bufferedReader.readLine()) != null) {
stringBuffer.append(line);
}
使用8 * 1024的任何理由? –