為什么會報錯 如何解決?
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
public class serverThread implements Runnable {
private Socket ss;
private String KehuDuanXinxi=null;
/*private int xianchengxulie;
private String KehuDuanName;
*/
public serverThread(Socket ss) {
this.ss = ss;
}
public void run() {
/*String string="客戶端你好";
socketoOutput(string);*/
KehuDuanXinxi = socketoInput();
socketoOutput("sdfe");
System.out.println("接收到服務(wù)器信息內(nèi)容是" + KehuDuanXinxi);
//serverThread ser= new serverThread(ss);
}
private InputStream is=null;
private InputStreamReader isr=null;
private BufferedReader br=null;
public String socketoInput() ?{
String string=null;
try {
is = ss.getInputStream();
isr = new InputStreamReader(is);
? ?br = new BufferedReader(isr);
? ? ? ?string = br.readLine();
? ? ? ?ss.shutdownInput();
? ? ? ?
? ? ? ?
? ? ? ?
os = ss.getOutputStream();
pw= new PrintWriter(os);
pw.write("服務(wù)器說 歡迎你");
pw.flush();
ss.shutdownOutput();
} catch (IOException e) {
// TODO 自動生成的 catch 塊
e.printStackTrace();
}finally {
try {
if (br!=null)
br.close();
if (isr!=null)
isr.close();
if (is!=null)
is.close();
if (pw!=null)
pw.close();
if(os!=null)
os.close();
} catch (IOException e) {
// TODO 自動生成的 catch 塊
e.printStackTrace();
}
}
//while((string=br.readLine())!=null){ xmlOutput(string); }
return string;
}
private OutputStream os=null;
private PrintWriter pw=null;
public void socketoOutput(String string) {
try {
os = ss.getOutputStream();
pw = new PrintWriter(os);
pw.write(string);
pw.flush();
ss.shutdownOutput();
} catch (IOException e) {
// TODO 自動生成的 catch 塊
e.printStackTrace();
} finally {
try {
if (pw!=null)
pw.close();
if(os!=null)
os.close();
} catch (IOException e) {
// TODO 自動生成的 catch 塊
e.printStackTrace();
}
}
}
public void xmlInput() {
}
public void xmlOutput(String string) {
}
}
這段代碼 會提示Socket is closed報錯