admin管理员组文章数量:1404605
Example:
I have
var r = new FileReader();
r.onload = function(e) {
drawGraph(r.result);
}
r.readAsText(f);
drawing a graph from the file f input by the user.
Is there a way to check to see if the file f has been changed and then re load it's content without needing for the user to pick the file again?
Example:
I have
var r = new FileReader();
r.onload = function(e) {
drawGraph(r.result);
}
r.readAsText(f);
drawing a graph from the file f input by the user.
Is there a way to check to see if the file f has been changed and then re load it's content without needing for the user to pick the file again?
Share Improve this question asked Mar 17, 2015 at 18:00 Damien King-AcevedoDamien King-Acevedo 671 gold badge1 silver badge6 bronze badges 4- Could I refresh the file? instead of waiting for it to change, just update the graph periodically automatically, or do I need user input for that? – Damien King-Acevedo Commented Mar 17, 2015 at 18:03
- You need user input for that. – Ginden Commented Mar 17, 2015 at 18:04
- 1 are you building a web app? i think you can do this in javascript with a chrome app. – Jeff Commented Mar 17, 2015 at 18:06
- A chrome app might work, thanks, I hadn't thought of that. – Damien King-Acevedo Commented Mar 17, 2015 at 18:13
1 Answer
Reset to default 3Yes, this can be achieved using Node.js's filesystem API which provides a "watch" function
NodeJS Filesystem API docs: https://nodejs/api/fs.html
Similar question: Observe file changes with node.js
fs.watch('somedir', function (event, filename) {
console.log('event is: ' + event);
if (filename) {
console.log('filename provided: ' + filename);
} else {
console.log('filename not provided');
}
});
本文标签: Can Javascript check a file for content changesStack Overflow
版权声明:本文标题:Can Javascript check a file for content changes? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744832867a2627455.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论