2012-09-13 109 views
0

我使用PrintWriter輸出對象。我寫數據通過out.println(一些數據),並用out.close在嘗試從服務器獲得響應時出現EOFException

URL url = new URL(myurl); 
URLConnection connection = null; 
PrintWriter out = null; BufferedReader br = null; connection = url.openConnection(); connection.setDoOutput(true); 
out = new PrintWriter(new OutputStreamWriter(connection.getOutputStream()),true); 
while(iterations) { 
    //print data on writer 
    out.println(object); 
} 
//closig print writer 
out.flush(); 
out.close(); 
//Response from server 
br = new BufferedReader(new InputStreamReader(connection.getInputStream())); // Get Exception in //this line EOF Exception 
String temp; 
while(temp = br.readLine() !=null) { 
    //do something 
} 
br.close(); 
+1

上傳您的代碼與錯誤代碼。 – Lucifer

+0

結束文件異常..?也許在服務器..你是否也編碼服務器端..? – ngesh

+1

發佈你的源代碼,你的logcat並且不僅在一個聲音中描述你的問題! –

回答

0
URL url = new URL(myurl); 
URLConnection connection = null; 
PrintWriter out = null; BufferedReader br = null; connection = url.openConnection(); connection.setDoOutput(true); 
out = new PrintWriter(new OutputStreamWriter(connection.getOutputStream()),true); 
while(iterations) 
    { 
//print data on writer 
out.println(object); 
} 
//closig print writer 
out.flush(); 

//Response from server 
br = new BufferedReader(new InputStreamReader(connection.getInputStream())); // Get Exception in //this line EOF Exception 
String temp; 
while(temp = br.readLine() !=null) 
{ //do something } 
out.close(); 

看一看代碼關閉它,你剛剛在把out.close代替br.close的結束。

相關問題