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");
}
}
}
}
}