file.js

来自「JSVM核心类库,收集了JAVA进行JSVM开发必用技术进行归纳,在实际项目应用」· JavaScript 代码 · 共 46 行

JS
46
字号
// Description:	js.io.File 类
// Author:	Changhua.Wan
// Version:	2004.03.06.01

_package("js.io");
_import("js.lang.Object");

function js.io.File(_path) {
	this.path = null;
	this.data = null;
	if (typeof(_path) == "string") this.path = _path;

	this.getFileName = function() {
		if (this.path == null) return null;
		var idx = this.path.lastIndexOf("\\");
		return this.path.substring(idx + 1);
	};
	
	this.getData = function() {
		if (this.path == null) return null;
		if (this.data == null) {
			try {
				this.data = Class.forName("js.io.FileReader").readBinary(this.path);
			} catch(ex) {
				ex.printStackTrace();	
			}
		}
		return this.data;
	};
	this.saveAs = function(_path) {
		try {
			Class.forName("js.io.FileWriter").writeBinary(_path, this.getData());
			this.path = _path;
		} catch(ex) {
			ex.printStackTrace();	
		}
	};
	this.size = function() {
		if (typeof(vbs_lenb) == "undefined")
			execScript("Function vbs_lenb(d) \n vbs_lenb = LenB(d) \n End Function","VBScript");
		return vbs_lenb(this.getData());
	}
}

js.io.File._extends("js.lang.Object");

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?