xml文件解析,同步xml文件描述的文件

来源:互联网 发布:笛卡尔的方法论知乎 编辑:程序博客网 时间:2024/06/05 02:40

用了五天时间用java写了个FileServer和FileClient,其中包含xmlresolver类,filebroadcast类等等

部分代码:

Server:

package Serverdefault;public class FileServerMain{public static void main(String[] args){ServerOn so=new ServerOn(9527);Thread t=new Thread(so);t.start();}}

package Serverdefault;import java.io.BufferedOutputStream;import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.net.ServerSocket;import java.net.Socket;import java.text.SimpleDateFormat;import java.util.Date;import java.util.HashMap;import java.util.Vector;import javax.swing.JOptionPane;public class ServerOn implements Runnable{private ServerSocket serverSocket;private Vector<ClientList> clientList;private HashMap clientMap;public ServerOn(int Port){clientList=new Vector<ClientList>();clientMap=new HashMap();try {serverSocket = new ServerSocket(Port);} catch (IOException e) {// TODO Auto-generated catch blockLog("At ServerOn.java ServerOn();"+"IOException error;"+e);e.printStackTrace();}Log("At ServerOn.java ServerOn();"+"启动服务成功;");}//记录日志函数 位置 bin/ServerLog.txtprotected void Log(String content){  SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  BufferedOutputStream bufferedOutputStream = null;  File file=new File("bin/ServerLog.txt");  String Log="\r\n"+(df.format(new Date())).toString()+"  ---->  ";  Log+=content+"\r\n";  try {   bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file, true));   bufferedOutputStream.write(Log.getBytes());  } catch (FileNotFoundException e) {   e.printStackTrace();  } catch(IOException e ){   e.printStackTrace();  }finally{   try {    bufferedOutputStream.close();   } catch (IOException e) {   JOptionPane.showMessageDialog(null,e,"错误信息",JOptionPane.ERROR_MESSAGE);   }  } }public void run() {// TODO Auto-generated method stubXMLFileListener xfl=new XMLFileListener(clientList,"FileSend",1000);xfl.Listen();while(true){try {Socket c=serverSocket.accept();//map没用到 ,Connection CSocket = new Connection(c,clientList,clientMap);Thread t=new Thread(CSocket);t.start();} catch (IOException e) {// TODO Auto-generated catch blockLog("At ServerOn.java run();"+"IOException error;"+e);e.printStackTrace();}}}public static void main(String[] str){ServerOn so=new ServerOn(9527);Thread t=new Thread(so);t.start();}}




完整代码去我的资源页

http://download.csdn.net/detail/qq910409576/6442505