filereader.js

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

JS
64
字号
// Description:	js.io.FileReader 类
// Author:	Changhua.Wan
// Version:	2004.03.06.01

_package("js.io");

_import("js.io.InputStream");

function js.io.FileReader() {

	this.filepath = null;

	if (typeof(arguments[0]) == "string")
		this.filepath = arguments[0];
	else if (typeof(arguments[0]) == "object" && typeof(arguments[0].path) == "string")
		this.filepath = arguments[0].path;
	else
		this.filepath = null;

	this.data = null;

	// 二进制操作
	this.read = function() {
		return (this.data = js.io.FileReader.readBinary(this.filepath));
	};
	this.readAll = function() {
		//TODO
	};	
	// 文本操作
	this.readLine = function() {
		//TODO	
	};
	this.readAll = function() {
		//TODO
	};

}
var _p = js.io.FileReader._implements("js.io.InputStream");
var _c = js.io.FileReader;

// 同源安全限制
_c.readBinary = function(_path) {
	try {
		var stream = new ActiveXObject("ADODB.Stream");
		stream.Mode = 3 ;
		stream.Type = 1 ;
		stream.open();
		stream.LoadFromFile(_path);
		var binaryStream = stream.Read();
		stream.close();
		return binaryStream;
	} catch(ex) {
		ex.printStackTrace();
	}
};
_c.readText = function(_path) {
	try {
		var fso = new ActiveXObject("Scripting.FileSystemObject");
		// TODO
	} catch(ex) {
		ex.printStackTrace();
	}
};

⌨️ 快捷键说明

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