JavaScript读取Txt文件
1
<html>
2
<head>
3
<title>new page</title>
4
<script>
5
function GetHeader(src) {
6
var ForReading=1;
7
var fso=new ActiveXObject("Scripting.FileSystemObject");
8
var f=fso.OpenTextFile(src,ForReading);
9
return(f.ReadAll());
10
}
11
var arr=GetHeader("C:\\a.txt").split("\r\n");
12
for(var i=0;i<arr.length;i++){
13
alert("第"+(i+1)+"行数据为:"+arr[i]);
14
}
15
</script>
16
</head>
17
<body>
18
</body>
19
</html>
![](/Images/OutliningIndicators/None.gif)
2
![](/Images/OutliningIndicators/None.gif)
3
![](/Images/OutliningIndicators/None.gif)
4
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
5
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
6
![](/Images/OutliningIndicators/InBlock.gif)
7
![](/Images/OutliningIndicators/InBlock.gif)
8
![](/Images/OutliningIndicators/InBlock.gif)
9
![](/Images/OutliningIndicators/InBlock.gif)
10
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
11
![](/Images/OutliningIndicators/InBlock.gif)
12
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
13
![](/Images/OutliningIndicators/InBlock.gif)
14
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
15
![](/Images/OutliningIndicators/None.gif)
16
![](/Images/OutliningIndicators/None.gif)
17
![](/Images/OutliningIndicators/None.gif)
18
![](/Images/OutliningIndicators/None.gif)
19
![](/Images/OutliningIndicators/None.gif)