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
- xml文件解析,同步xml文件描述的文件
- xml文件的解析
- XML文件的解析
- XML文件的解析
- xml文件的解析
- xml文件的解析
- XML文件的解析
- XML文件的解析
- XML文件的解析
- xml文件的解析
- xml文件的解析
- XML文件的解析
- xml文件的解析
- XML 文件的解析
- XML文件的解析
- xml文件的解析
- xml文件的解析
- XML文件的解析
- JAVA网页浏览器
- MySQL SQL 分析 - 参数化查询 vs query cache 功能
- MSP430F5438 ADC12学习笔记
- UITableView获取cell的row值(解决自定义cell里的button通过点击无法获得cell的indexpath的问题)
- linux下安装protobuf教程+示例
- xml文件解析,同步xml文件描述的文件
- The process was terminated due to an internal error in the .NET Runtime at IP 7915EE73 (79140000) wi
- 内部类小练习
- 黑马程序员_<<面线对象(继承,abstract,interface,final)---02>>
- 核心系统某业务超时的问题分析
- weka分类算法精度效率汇总
- 2013年欧朋php笔试回顾
- java面试题及答案(1)
- OpenCart高级优惠券功能模块(Advanced Coupons Modules)