简体   繁体   English

使用其他扩展名JavaScript保存文件

[英]Save file with different extension javascript

So, I'm currently saving a file with .TXT extension, but I would like to change it to save a .INI extension. 因此,我当前正在保存带有.TXT扩展名的文件,但是我想更改它以保存.INI扩展名。

I'm using this code on my js to save a .TXT file: 我在我的js上使用以下代码来保存.TXT文件:

blob = new Blob([file], {type: "text/plain;charset=utf-8"})
        saveAs(blob, name)

This .INI extension can be edited with notepad, so I would like to know if it is possible to download a file with .INI extension. 可以使用记事本编辑此.INI扩展名,因此我想知道是否可以下载具有.INI扩展名的文件。

Thanks 谢谢

Because you haven't posted the implementation for the saveAs function, there really is no way to know how it works. 因为您尚未发布saveAs函数的实现,所以实际上没有办法知道它是如何工作的。 I would try the following: 我会尝试以下方法:

var name = 'myfile.ini';
blob = new Blob([file], {type: "text/plain;charset=utf-8"});
saveAs(blob, name);

That's the best I can say without knowing the library that you're using and how it's implemented. 在不知道您正在使用的库及其实现方式的情况下,这是我能说的最好的。

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

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