js创建并读取txt文件的内容

<SCRIPT>

function Write2Text()
{

//如果是服务器端就是Server.CreateObject("Scripting.FileSystemObject");
var fso = new ActiveXObject("Scripting.FileSystemObject"); 
var f = fso.CreateTextFile("E://a.txt", true);
 
f.write("nihao")
 f.WriteBlankLines(1)

f.Close();
}

 


function getPath()
    {
    //document.getElementById("tt").value = "";
    var ForReading = 1;
    var filePath =  "E://a.txt"
    if(filePath == "")
    return;
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var textFile = fso.GetFile(filePath);
    var ts = fso.OpenTextFile(filePath, ForReading);
    var result = ts.ReadAll();
 
   alert(result)
 }
 
 
 

  </script>

<BODY>
<input type="button" value="写入" onClick="Write2Text()">
<input type="button" value="读取" onClick="getPath()">

</BODY>
 

 

你可能感兴趣的:(function,服务器,input,button)