简体   繁体   English

在Firefox扩展名中创建文件时出错

[英]Error creating file in firefox extension

I am trying to create a file in the extension using this code: 我正在尝试使用以下代码在扩展名中创建文件:

Components.utils.import("resource://gre/modules/FileUtils.jsm");
var file = new FileUtils.File("C:\\Windows\\hello.txt");

But nothing happens.The file doesn't appear 但是什么也没发生。文件没有出现

Any ideas? 有任何想法吗?

Your file var is an object that represents a file at the location you specified. 您的文件var是一个对象,代表您指定位置的文件。 Creating this file object does not create a file directly (you might instead choose to read from the file, for example). 创建此文件对象不会直接创建文件(例如,您可以选择从文件中读取)。

You can now use the nsIFile API to manipulate the file object. 现在,您可以使用nsIFile API来操作文件对象。 For example, you can create a file at that location: 例如,您可以在该位置创建文件:

file.create(file.NORMAL_FILE_TYPE, parseInt("0600", 8));

Note that Windows UAC can cause file access to fail. 请注意,Windows UAC可能导致文件访问失败。 You might want to try: 您可能要尝试:

file.isWriteable();

but ultimately you might find that it's not possible to write to directories that UAC is protecting so you can instead choose a non-protected location, perhaps using the special directory definitions explained on this useful MDN page: https://developer.mozilla.org/en-US/docs/Code_snippets/File_I_O 但是最终您可能会发现无法写入UAC保护的目录,因此您可以选择一个不受保护的位置,也许使用此有用的MDN页面上解释的特殊目录定义: https : //developer.mozilla.org / zh-CN / docs / Code_snippets / File_I_O

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM