我正在开发一个连接到Web服务器并接收响应的应用程序.我将此响应保存在设备内部存储器的txt文件中.现在我需要逐行读取整个文件,因为如果我尝试读取整个文件,它会抛出一个OutofMemoryException.所以现在我正在使用以下代码编写和读取文件:
httpclient = new DefaultHttpClient();
httppost = new HttpPost("http://www.rpc.probnata.com");
postParameters = new ArrayList();
postParameters.add(new BasicNameValuePair("debug_data","1"));
httppost.setEntity(new UrlEncodedFormEntity(postParameters));
HttpResponse response = httpclient.execute(httppost);
Log.w("Response ","Status line : "+ response.getStatusLine().toString());
buffer = EntityUtils.toByteArray(response.getEntity());
FileOutputStream out = this.openFileOutput("response",this.MODE_PRIVATE);
out.write(buffer);
out.close();
阅读文件:
public void parseResponse(){
try {
File myDir