首页 > > 详细

辅导Java server 编程、Java server 语言讲解留学生、讲解Java、Java设计辅导

package server;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
* Created by Administrator on 2016/4/13.
*/
public class server {
public static void main(String argv[]) throws Exception
{
String ClientSentence;
String capitalizedSentence;
ServerSocket welcomeSocket = new ServerSocket(6789);
while(true){
File directory = new File("");//
String total = directory.getCanonicalPath() ;
Socket connectionSocket = welcomeSocket.accept();
BufferedReader infromClient =
new BufferedReader(new
InputStreamReader(connectionSocket.getInputStream()));
DataOutputStream utToClient =
new DataOutputStream(connectionSocket.getOutputStream());
ClientSentence = infromClient.readLine();
if(ClientSentence.equals("abc")){
// outToClient.writeBytes(total+'\n');
File file=new File(total);//
String test[];
test=file.list();
for(int i=0;i {
outToClient.writeBytes(test[i]+'\n');
// System.out.println(test[i]);
}
outToClient.writeBytes("end"+'\n');
}
else
{
try{
RandomAccessFile in=new RandomAccessFile(ClientSentence,"r");
String s;
total="";
while((s=in.readLine())!=null){
total=total+s;
}
outToClient.writeBytes(total+'\n');
in.close();
}
catch(Exception e){
outToClient.writeBytes(ClientSentence+" not found \n");
}
}

}
}

}

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!