posts - 325,  comments - 25,  trackbacks - 0
          1.用JS創建文件
          var fso, f1;
          fso = new ActiveXObject("Scripting.FileSystemObject");
          f1 = fso.CreateTextFile("c:\\testfile.txt", true);

          2.用JS創建并寫入數據
          function CreateFile()
          {
             var fso, tf;
             fso = new ActiveXObject("Scripting.FileSystemObject");
             tf = fso.CreateTextFile("c:\\testfile.txt", true);
             // 寫一行,并且帶有新行字符。
             tf.WriteLine("Testing 1, 2, 3.") ;
             // 向文件寫三個新行字符。 
             tf.WriteBlankLines(3) ;
             // 寫一行。
             tf.Write ("This is a test.");
             tf.Close();
          }
          3.用JS讀取數據
          function ReadFiles()
          {
             var fso, f1, ts, s;
             var ForReading = 1;
             fso = new ActiveXObject("Scripting.FileSystemObject");
             f1 = fso.CreateTextFile("c:\\testfile.txt", true);
             // 寫一行。
            // Response.Write("Writing file <br>");
             f1.WriteLine("Hello World");
             f1.WriteBlankLines(1);
             f1.Close();
             // 讀取文件的內容。
            // Response.Write("Reading file <br>");
             ts = fso.OpenTextFile("c:\\testfile.txt", ForReading);
             s = ts.ReadLine();
            // Response.Write("File contents = '" + s + "'");
            alert(s);
             ts.Close();
          }
          4.移動、復制和刪除文件
          任務 方法
          移動文件 File.Move 或 FileSystemObject.MoveFile
          復制文件 File.Copy 或 FileSystemObject.CopyFile
          刪除文件 File.Delete 或 FileSystemObject.DeleteFile

          function ManipFiles()
          {
             var fso, f1, f2, s;
             fso = new ActiveXObject("Scripting.FileSystemObject");
             f1 = fso.CreateTextFile("c:\\testfile.txt", true);
             Response.Write("Writing file <br>");
             // 寫一行。
             f1.Write("This is a test.");
             // 關閉文件。
             f1.Close();
             Response.Write("Moving file to c:\\tmp <br>");
             // 獲取 C 的根目錄(C:\)中的文件的句柄。
             f2 = fso.GetFile("c:\\testfile.txt");
             // 把文件移動到 \tmp 目錄。
             f2.Move ("c:\\tmp\\testfile.txt");
             Response.Write("Copying file to c:\\temp <br>");
             // 把文件復制到 \temp 目錄。
             f2.Copy ("c:\\temp\\testfile.txt");
             Response.Write("Deleting files <br>");
             // 獲得文件當前位置的句柄。
             f2 = fso.GetFile("c:\\tmp\\testfile.txt");
             f3 = fso.GetFile("c:\\temp\\testfile.txt");
             // 刪除文件。
             f2.Delete();
             f3.Delete();
             Response.Write("All done!");
          }
          posted on 2008-07-11 11:30 長春語林科技 閱讀(7013) 評論(1)  編輯  收藏 所屬分類: js

          FeedBack:
          # re: js 操作文件[未登錄]
          2016-06-19 20:49 | 00
          00  回復  更多評論
            
          <2016年6月>
          2930311234
          567891011
          12131415161718
          19202122232425
          262728293012
          3456789

           

          長春語林科技歡迎您!

          常用鏈接

          留言簿(6)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          相冊

          收藏夾

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 托里县| 泸定县| 米易县| 当涂县| 神农架林区| 巍山| 丹寨县| 江都市| 甘洛县| 南汇区| 清远市| 赤水市| 富平县| 三明市| 兴宁市| 双桥区| 饶平县| 阳朔县| 宾川县| 彝良县| 区。| 攀枝花市| 安图县| 深泽县| 乡宁县| 台湾省| 磴口县| 仁布县| 康定县| 白河县| 天柱县| 镇江市| 华坪县| 阜新市| 潼南县| 嘉义县| 乌拉特中旗| 萨迦县| 英吉沙县| 招远市| 南郑县|