我有一个这样的XML配置文件:
<configuration>
<items>
<item key="KEY_NAME">
3
</item>
</items>
</configuration>
我需要一些库来读取(仅读取(文件值,但可以在不重新启动应用程序的情况下检测更改(例如,更改值 3 表示 5(。
我为此使用了njupiter,但这个项目已被弃用。我找到了MiniFSWatcher,你知道其他图书馆吗?
谢谢
为什么不使用官方 https://learn.microsoft.com/en-us/dotnet/api/system.io.filesystemwatcher?view=netframework-4.8 类来监视文件系统?
示例如下:
using (FileSystemWatcher watcher = new
FileSystemWatcher())
{
watcher.Path = args[1];
// Watch for changes in LastAccess and LastWrite times, and
// the renaming of files or directories.
watcher.NotifyFilter = NotifyFilters.LastAccess
| NotifyFilters.LastWrite
| NotifyFilters.FileName
| NotifyFilters.DirectoryName;
// Only watch text files.
watcher.Filter = "*.xml";
// Add event handlers.
watcher.Changed += OnChanged;
// Begin watching.
watcher.EnableRaisingEvents = true;
// Wait for the user to quit the program.
Console.WriteLine("Press 'q' to quit the sample.");
while (Console.Read() != 'q') ;
}
}
// Define the event handlers.
private static void OnChanged(object source, FileSystemEventArgs e) =>
// Specify what is done when a file is changed, created, or deleted.
Console.WriteLine($"File: {e.FullPath} {e.ChangeType}");
}
在 on changed 事件中,可以重新加载文件和值。
这就是Njupiter现在被弃用的原因。