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

用了五天时间用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="\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 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值