javascript 文件操作

javascript 文件操作

目录:

javascript读取本地文件
javascript新建文件
字符串spilt函数


程序
javascript读取本地文件
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script type="text/javascript">
<!--
function ReadTxt(file,oTxt){
var path=file.value ;
var fso=new ActiveXObject( "Scripting.FileSystemObject");
var f=fso.OpenTextFile(path,1);
oTxt.value
=f.ReadAll(); //document.write(f.ReadAll());
}
//-->
</script>
</head>
<body>
<form>
<input type= "file" name= "file1"> <input type=button onclick= "ReadTxt(file1,txt)" value= "Read"> <br><br><br>
<textarea rows="10" cols="100" name= "txt"> </textarea>
</form>
</body>
</html>



javascript新建文件
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script type="text/javascript">
<!--
function buildnew(){
var fso=new ActiveXObject( "Scripting.FileSystemObject");
var f1 = fso.createtextfile("d:\\new.txt",true);
}
//-->
</script>
</head>
<body>
<form>
<input type=button onclick= "buildnew()" value= "new">
</form>
</body>
</html>


字符串spilt函数
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script type="text/javascript">
<!--
function buildnew(){
var str="How are you doing today?"

document.write(str.split(
" ") + "<br />")
document.write(str.split(
"") + "<br />")
document.write(str.split(
" ",3))
}
//-->
</script>
</head>
<body>
<form>
<input type=button onclick= "buildnew()" value= "new">
</form>
</body>
</html>

posted @ 2011-06-09 21:02  wangkangluo1  阅读(743)  评论(0编辑  收藏  举报