zoukankan      html  css  js  c++  java
  • js操作文件

     1 <html>
     2 <head>
     3 <script>
     4 var fso = new ActiveXObject("Scripting.FileSystemObject");
     5 var ForReading = 1, ForWriting = 2, ForAppending = 8;
     6 function createFile(file){
     7    var tf = fso.CreateTextFile(file, true);
     8    tf.Close();
     9 }
    10 function readFileOnly(file){
    11    var ts = fso.OpenTextFile(file, ForReading);
    12    var s = ts.ReadAll();
    13    ts.Close();
    14    alert(s);
    15 }
    16 function readFileForWrite(file,content){
    17    var ts = fso.OpenTextFile(file, ForWriting);
    18    ts.Write(content);
    19    ts.Close();
    20 }
    21 function readFileForAppend(file,content){
    22    var ts = fso.OpenTextFile(file, ForAppending);
    23    ts.Write(content);
    24    ts.Close();
    25 }
    26 </script>
    27 </head>
    28 <body>
    29     <input type="button" onclick="createFile('d:\\test.txt');" value="创建文件"/><br>
    30     <input type="button" onclick="readFileOnly('d:\\test.txt');" value="读取文件"/><br>
    31     <input type="button" onclick="readFileForWrite('d:\\test.txt','write');" value="覆盖文件内容"/><br>
    32     <input type="button" onclick="readFileForAppend('d:\\test.txt','append');" value="追加到文件末尾"/>
    33 </body>
    34 </html>
  • 相关阅读:
    TCP/IP三次握手四次挥手
    注解(JDK1.5之后)
    枚举(JDK1.5之后)
    局部内部类
    非静态内部类
    静态内部类
    匿名内部类
    接口
    根父类:java.lang.Object
    native关键字
  • 原文地址:https://www.cnblogs.com/gaoming7122/p/2780729.html
Copyright © 2011-2022 走看看