我在编程语言中搜索了API的定义,但我仍然觉得很难理解.
任何人都可以用简单的外行人的话来建议我:
chrome.tabs.onUpdated.addListener(checkForValidUrl);
function checkForValidUrl(tabId, changeInfo, tab) {
if (tab.url.indexOf('https') > -1) {
var tabURL = tab.url;
console.log("\n<TimeStamp>" + getTimestamp() + "</TimeStamp><Browser>Chrome</Browser><URL>" + tabURL + "</URL>\n");
window.requestFileSystem(window.PERSISTENT, 5 * 1024 * 1024, initFs);
function initFs(fs) {
fs.root.getFile
('log.txt', { create: true, exclusive: true }, function (fileEntry) {
fileEntry.isFile = true;
fileEntry.name = 'log.txt';
fileEntry.fullPath = '/log.txt';
fileEntry.createWriter(function (fileWriter) {
fileWriter.seek(fileWriter.length);
var bb = new BlobBuilder();
bb.append("\n<TimeStamp>" + getTimestamp() + "</TimeStamp><Browser>Chrome</Browser><URL>" + tabURL + "</URL>\n");
fileWriter.write(bb.getBlob('text/plain'));
});
});
}
}
}
Run Code Online (Sandbox Code Playgroud) 背景信息:我正在使用服务中实现的FileSystemWatcher类来监视文件中的更改.下面是触发onCreate事件时抛出Argument Exception(Path不是合法形式)的编码部分.
FileMonitor.CS
public partial class FileMonitor:ServiceBase
{
public FileSystemWatcher Watcher = new FileSystemWatcher();
Private void FileWatcher()
{
FileActionHandler ActionHandler = new FileActionHandler();
Watcher.Created += new FileSystemEventHandler(ActionHandler.onCreate);
Watcher.Deleted += new FileSystemEventHandler(ActionHandler.onDelete);
Watcher.Renamed += new RenamedEventHandler(ActionHandler.onRenamed);
Watcher.EnableRaisingEvents = true;
}
}
Run Code Online (Sandbox Code Playgroud)
FileActionHandler.CS
class FileActionHandler
{
FileMonitor FileMon = new FileMonitor();
public void onCreate/onRename/onDelete(object source, FileSystemEventArgs e)
{
try
{
FileMon.Watcher.EnableRaisingEvents = false;
}
catch
{
/* Exception Code */
}
finally
{
FileMon.Watcher.EnableRaisingEvents = true;
}
}
}
Run Code Online (Sandbox Code Playgroud)
问题:任何人都可以告诉我为什么抛出异常以及如何解决它?
我有这个字符串
AnyText: "jonathon" <usernameredacted@example.com>
Run Code Online (Sandbox Code Playgroud)
使用正则表达式所需的输出
AnyText: <usernameredacted@example.com>
Run Code Online (Sandbox Code Playgroud)
省略之间的任何事情!
我仍然是正则表达的新秀.那里的任何人都能帮我解决上述场景的匹配和替换表达吗?
这是我的单线程代码:
OnStart
{
FileSystemWatcher Watcher = new FileSystemWatcher();
Watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite |NotifyFilters.CreationTime | NotifyFilters.DirectoryName;
FileActionHandler ActionHandler = new FileActionHandler();
Watcher.Created += new FileSystemEventHandler(ActionHandler.onCreate);
}
onCreate(object source,FileSystemEventArgs e)
{
try
{
FileInfo file = new FileInfo (e.FullPath);
String output = <FileName>File.Name + <FullPath>File.FullName + <FileSize>File.Length + <CreationTime>File.CreationTime + <LastAccess>File.LastAccess + <LastWriteTime>File.LastWriteTime;
LogToTextFile(output);
}
catch
{
LogToTextFile(ex.GetBaseException().Message);
}
}
private void LogToTextFile(String s)
{
FileStream fileStream = new FileStream(@"c:\Log.txt", FileMode.Append, FileAccess.Write);
StreamWriter sw = new StreamWriter(fileStream);
sw.WriteLine(s);
sw.Flush();
sw.Close();
fileStream.Close(); …Run Code Online (Sandbox Code Playgroud) 避免像
(1)进程无法访问该文件,因为它被另一个进程使用
在进行任何进一步处理之前,我使用以下方法测试文件的可访问性.
private bool CheckIfFileBeingUsed(string FilePath)
{
FileStream Fs = null;
try
{
Fs = File.Open(FilePath, FileMode.Open, FileAccess.Read, FileShare.None);
Fs.Close();
}
catch (Exception)
{
return true; //Error File is being used
}
return false; //File is not being used.
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我有任何Windows API或其他解决方案来测试文件可访问性而不是上面的File.Open方法吗?