1
我試圖調用Web服務讀性反應,響應包含一個大的字符串,走出內存問題的代碼是獲取內存不足的錯誤,同時從Web服務
URL u = new URL(SharedVariables.server);
URLConnection uc = u.openConnection();
HttpURLConnection connection = (HttpURLConnection) uc;
connection.setConnectTimeout(SharedVariables.connectionTimedOutValue);
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestProperty("SOAPAction", SOAP_ACTION);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-type", "text/xml; charset=utf-8");
String xmldata = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"> "+
"<soap:Body>"+
"<GetCaseCriminalTicketLinks xmlns=\"http://tempuri.org/\">"+
Req.getRequestXml()+
"</GetCaseCriminalTicketLinks>"+
"</soap:Body>"+
"</soap:Envelope>";
OutputStream out = connection.getOutputStream();
Writer wout = new OutputStreamWriter(out);
wout.write(xmldata);
wout.flush();
out.flush();
BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()),8 * 1024);
String result;
while ((result=rd.readLine()) != null) {
int length = result.length();
String temp = result.substring(316, (length - 100));
JSONObject tempJson = new JSONObject(temp);}
日誌是
Caused by: java.lang.OutOfMemoryError
at java.lang.String.<init>(String.java:513)
at java.lang.AbstractStringBuilder.toString(AbstractStringBuilder.java:650)
at java.lang.StringBuilder.toString(StringBuilder.java:664)
at java.io.BufferedReader.readLine(BufferedReader.java:398)
此行是造成
while ((result=rd.readLine()) != null)
有什麼建議?
感謝
有多久行你想讀什麼書? – aioobe 2012-03-10 07:11:37
它將在1mb左右 – Kishore 2012-03-10 07:13:55