【问题标题】:Uncaught TypeError: Failed to construct 'File': 2 arguments required, but only 1 present未捕获的类型错误:无法构造“文件”:需要 2 个参数,但只有 1 个存在
【发布时间】:2018-11-16 20:04:16
【问题描述】:

我正在编写一个 JavaScript 以使用 Google Chrome 将文件写入 aframe 虚拟现实应用程序中的本地目录。

在调试时我得到了这个错误:

Uncaught TypeError: Failed to construct 'File': 2 arguments required, but `only 1 present.`

我从其他人那里得到了以下代码,但我不明白为什么谷歌浏览器说这需要 2 个参数?

<script>
/// write to file
var txtFile = "skycolour.txt";
var file = new File(txtFile);
var str = "My string of text";

file.open("w"); // open file with write access
file.writeln("First line of text");
file.writeln("Second line of text " + str);
file.write(str);
file.close();
</script>

感谢您的帮助。

Image of the error for your reference

【问题讨论】:

标签: javascript html google-chrome


【解决方案1】:
// Requiring fs module in which 
// writeFile function is defined. 

 const fs = require('fs') 

// Data which will write in a file. 

let data = "Learning how to write in a file."

// Write data in 'Output.txt' . 

fs.writeFile('Output.txt', data, (err) => { 

   // In case of a error throw err. 

    if (err) throw err; 
}) 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多