[英]Print file content in JavaScript (implicity pass file path not use input browser box)
I have this code below which prints a file content to the log.我在下面有这段代码,它将文件内容打印到日志中。 This works fine.
这工作正常。
Now, I want to do the same but instead of getting the file from input browse box, I want to write it implicitly like:现在,我想做同样的事情,但不是从输入浏览框中获取文件,而是想隐式地编写它,例如:
var file = 'c:\\1.txt';
How can I do so?我怎么能这样做?
<!DOCTYPE html>
<html>
<head>
<title>
Log Printer in Javascript
</title>
<input type="file" id="fileinput"/>
<script type="text/javascript">
function printFileToLog(evt) {
var file = this.files[0];
var reader = new FileReader();
reader.onload = function(progressEvent){
console.log(this.result);
};
reader.readAsText(file);
};
document.getElementById('fileinput').addEventListener('change', printFileToLog, false);
</script>
</head>
</html>
That's not possible.那是不可能的。
You can't just read any file from user's computer unless they explicitly allow you to do it.您不能只从用户的计算机中读取任何文件,除非他们明确允许您这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.