filesystemwatch java_C#方法的委托和java中的回调

先看个效果20130415.

C#监视文件夹,显示文件夹操作到listView上

caf09cc96d845dcf31f2e0dfeb6e7a09.png

代码实现,以前在学校生活写的,就几句代码

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.IO;

using System.Threading;

namespace FileWatch

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private FileSystemWatcher watcher = new FileSystemWatcher();

private delegate void mydel(String str);//声明一个委托

private mydel MyDel;//声明一个全局的委托实例

///

/// 选择文件夹并开始监视

///

///

///

private void btnChooseFolder_Click(object sender, EventArgs e)

{

FolderBrowserDialog fd = new FolderBrowserDialog();

if (fd.ShowDialog() == DialogResult.OK)

{

txbFolder.Text = fd.SelectedPath;

FileSystemWatch(txbFolder.Text);

MyDel = new mydel(AddTolist);

}

}

///

/// 增加到列表

///

///

private void AddTolist(string str)

{

lstbResult.Items.Add(str);

}

///

/// 获取对文件夹操作的信息

///

/// 信息字符串

private void GetInfo(string str)

{

lstbResult.Invoke(MyDel, str);

}

#region 文件监视操作

private void FileSystemWatch(string path)

{

watcher.Path = path;

watcher.Created += new FileSystemEventHandler(OnCreate);

watcher.Deleted += new FileSystemEventHandler(OnDelete);

watcher.Renamed += new RenamedEventHandler(OnRenamed);

watcher.IncludeSubdirectories = true;

watcher.EnableRaisingEvents = true;

}

private void OnChanged(object source, FileSystemEventArgs e)

{

GetInfo(e.Name + " 被 修改. " + DateTime.Now.ToShortTimeString());

}

private void OnCreate(object source, FileSystemEventArgs e)

{

GetInfo(e.Name + " 被 创建." + DateTime.Now.ToShortTimeString());

}

private void OnDelete(object source, FileSystemEventArgs e)

{

GetInfo(e.Name + " 被 删除." + DateTime.Now.ToShortTimeString());

}

private void OnRenamed(object source, FileSystemEventArgs e)

{

GetInfo(e.Name + " 被 重命名" + DateTime.Now.ToShortTimeString());

}

#endregion

}

}

java回调

public interface CallBack{

public void callBack();

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值