java多个输入输出流写在一个方法里,只能执行一个,是么?看下面程序
privateSockets1;publicClientThread(Sockets1){this.s1=s1;}publicvoidrun(){try{Buffered...
private Socket s1;
public ClientThread(Socket s1)
{
this.s1=s1;
}
public void run()
{
try{
BufferedReader br=null;
br=new BufferedReader(new InputStreamReader(s1.getInputStream()));
String str=null;
str = br.readLine();
System.out.println(str);
pro=Runtime.getRuntime().exec("cmd /c tasklist");
BufferedReader ar=null;
ar = new BufferedReader(new InputStreamReader(pro.getInputStream()));
String msg = null;
msg = ar.readLine();//问题1,无法读出tasklist信息,只显示执行两字
System.out.println(msg+"执行");
PrintWriter out=null;
out=new PrintWriter(new OutputStreamWriter(s1.getOutputStream()));
out.println(msg);//问题2,无法将msg字符发出去
out.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
这个程序客户端和服务端代码都在这http://tieba.baidu.com/f?kz=1104377355 展开
public ClientThread(Socket s1)
{
this.s1=s1;
}
public void run()
{
try{
BufferedReader br=null;
br=new BufferedReader(new InputStreamReader(s1.getInputStream()));
String str=null;
str = br.readLine();
System.out.println(str);
pro=Runtime.getRuntime().exec("cmd /c tasklist");
BufferedReader ar=null;
ar = new BufferedReader(new InputStreamReader(pro.getInputStream()));
String msg = null;
msg = ar.readLine();//问题1,无法读出tasklist信息,只显示执行两字
System.out.println(msg+"执行");
PrintWriter out=null;
out=new PrintWriter(new OutputStreamWriter(s1.getOutputStream()));
out.println(msg);//问题2,无法将msg字符发出去
out.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
这个程序客户端和服务端代码都在这http://tieba.baidu.com/f?kz=1104377355 展开
若以下回答无法解决问题,邀请你更新回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询