2008-04-16
js 读写本地文件整理
简单明了比《Javascript之文件操作 (IE)》实用!
<script>
/*
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 readFile(filename){
var fso = new ActiveXObject("Scripting.FileSystemObject");
var f = fso.OpenTextFile(filename,1);
var s = "";
while (!f.AtEndOfStream)
s += f.ReadLine()+"\n";
f.Close();
return s;
}
//写文件
function writeFile(filename,filecontent){
var fso, f, s ;
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.OpenTextFile(filename,8,true);
f.WriteLine(filecontent);
f.Close();
alert('ok');
}
</script>
<html>
<input type="text" id="in" name="in" />
<input type="button" value="Write!" onclick="writeFile('c:/12.txt',document.getElementById('in').value);"/><br><br>
<input type="button" value="Read!" onclick="document.getElementById('show').value=readFile('c:/12.txt');"/><br>
<textarea id="show" name="show" cols="50" rows="8" >
</textarea>
</html>
<script>
/*
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 readFile(filename){
var fso = new ActiveXObject("Scripting.FileSystemObject");
var f = fso.OpenTextFile(filename,1);
var s = "";
while (!f.AtEndOfStream)
s += f.ReadLine()+"\n";
f.Close();
return s;
}
//写文件
function writeFile(filename,filecontent){
var fso, f, s ;
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.OpenTextFile(filename,8,true);
f.WriteLine(filecontent);
f.Close();
alert('ok');
}
</script>
<html>
<input type="text" id="in" name="in" />
<input type="button" value="Write!" onclick="writeFile('c:/12.txt',document.getElementById('in').value);"/><br><br>
<input type="button" value="Read!" onclick="document.getElementById('show').value=readFile('c:/12.txt');"/><br>
<textarea id="show" name="show" cols="50" rows="8" >
</textarea>
</html>
发表评论
提醒: 该博客已发表在公共论坛,博客所有留言会成为论坛回贴,留言请注意遵守论坛发贴规则
- 浏览: 1281 次
- 性别:

- 来自: 沈阳

- 详细资料
搜索本博客
最近加入圈子
链接
最新评论
-
web service 学习资料搜集 ...
Joo 写道因为AXIS不支持jax-ws 所以选择用axis2 但是貌似除了多 ...
-- by jnn -
web service 学习资料搜集 ...
因为AXIS不支持jax-ws 所以选择用axis2但是貌似除了多多出来几种Da ...
-- by Joo -
web service 学习资料搜集 ...
cxf是基于JAX-RS 0.6 REST实现的
-- by melin -
web service 学习资料搜集 ...
CXF也有了rest的解决方案
-- by 小嘴看世界 -
web service 学习资料搜集 ...
谢谢! 等我把这个搞懂后我会关注其他的
-- by java_lk






评论排行榜