xml文件解析,同步xml文件描述的文件
发布时间:2020-12-15 23:20:13 所属栏目:百科 来源:网络整理
导读:用了五天时间用java写了个FileServer和FileClient,其中包含xmlresolver类,filebroadcast类等等 部分代码: Server: package Serverdefault;public class FileServerMain{public static void main(String[] args){ServerOn so=new ServerOn(9527);Thread t=n
用了五天时间用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 block Log("At ServerOn.java ServerOn();"+"IOException error;"+e); e.printStackTrace(); } Log("At ServerOn.java ServerOn();"+"启动服务成功;"); } //记录日志函数 位置 bin/ServerLog.txt protected 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="rn"+(df.format(new Date())).toString()+" ----> "; Log+=content+"rn"; 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 stub XMLFileListener 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 block Log("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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |