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>
  • 相关阅读:
    简单测试
    纸玫瑰
    Java 字符串编码 (保存成txt测试)
    创建 Filter
    jee中文名图片+tomcat ==> 中文乱码的另类处理(未成功)
    dom4j_01_02
    dom4j_01_01
    Java 字符串编码
    websocket

  • 原文地址:https://www.cnblogs.com/gaoming7122/p/2780729.html
Copyright © 2011-2022 走看看