/**
object.OpenTextFile(filename[, iomode[, create[, format]]])
参数
object
必选项。object 应为 FileSystemObject 的名称。
filename
必选项。指明要打开文件的字符串表达式。
iomode
可选项。可以是三个常数之一:ForReading 、 ForWriting 或 ForAppending 。
create
可选项。Boolean 值,指明当指定的 filename 不存在时是否创建新文件。如果创建新文件则值为 True ,如果不创建则为 False 。如果忽略,则不创建新文件。
format
可选项。使用三态值中的一个来指明打开文件的格式。如果忽略,那么文件将以 ASCII 格式打开。
设置
iomode 参数可以是下列设置中的任一种:
常数 值 描述
ForReading 1 以只读方式打开文件。不能写这个文件。
ForWriting 2 以写方式打开文件
ForAppending 8 打开文件并从文件末尾开始写。
format 参数可以是下列设置中的任一种:
值 描述
TristateTrue 以 Unicode 格式打开文件。
TristateFalse 以 ASCII 格式打开文件。
TristateUseDefault 使用系统默认值打开文件。
*/
(function ($) {
$.fn.BaseDAO = function(option) {
option = $.extend({
dataPath : $.fn.config.dataPath
}, option);
var self = this;
var fso = {};
/**
* 获得 config.js 中的dataPath值
*/
var dataPath = option.dataPath;
$.extend(this, {
/**
* 初始化
* @returns
*/
_init : function() {
/**
* 创建 Active 读写文件
*/
fso = new ActiveXObject("Scripting.FileSystemObject");
},
/**
* 读取文件内容
* @param dataPath 文件地址
* @returns
*/
read : function(dataPath) {
var file = undefined;
var content = "";
try {
file = fso.OpenTextFile(dataPath, 1, true);
while (!file.AtEndOfStream) {
content += file.ReadLine();
}
} finally {
if (file) {
file.Close();
}
}
/**
* 将JSON字符串转换为 JSON对象
*/
return eval('(' + content + ')');
},
/**
* 向文件写入内容
* @param dataPath 文件地址
* @param content 内容
* @returns
*/
write : function(dataPath, content) {
var file = undefined;
try {
file = fso.OpenTextFile(dataPath, 2, true);
/**
* 将JSON对象转换为 JSON字符串
*/
file.WriteLine(JSON.stringify(content));
file.close();
} finally {
if (file) {
file.Close();
}
}
}
});
this._init();
return this;
};
})(jQuery);
BaseDAO.js
最新推荐文章于 2024-09-19 16:58:12 发布
本文介绍如何利用FileSystemObject (FSO) 进行文件的读取与写入操作。通过JavaScript实现,具体包括以不同模式打开文件、读取文件内容及向文件中写入内容的方法。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
Wan2.2-T2V-A5B
文生视频
Wan2.2
Wan2.2是由通义万相开源高效文本到视频生成模型,是有50亿参数的轻量级视频生成模型,专为快速内容创作优化。支持480P视频生成,具备优秀的时序连贯性和运动推理能力
4847

被折叠的 条评论
为什么被折叠?



