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

          2.用JS創(chuàng)建并寫入數(shù)據(jù)
          function CreateFile()
          {
             var fso, tf;
             fso = new ActiveXObject("Scripting.FileSystemObject");
             tf = fso.CreateTextFile("c:\\testfile.txt", true);
             // 寫一行,并且?guī)в行滦凶址?br />    tf.WriteLine("Testing 1, 2, 3.") ;
             // 向文件寫三個(gè)新行字符。 
             tf.WriteBlankLines(3) ;
             // 寫一行。
             tf.Write ("This is a test.");
             tf.Close();
          }
          3.用JS讀取數(shù)據(jù)
          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();
             // 讀取文件的內(nèi)容。
            // 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.移動(dòng)、復(fù)制和刪除文件
          任務(wù) 方法
          移動(dòng)文件 File.Move 或 FileSystemObject.MoveFile
          復(fù)制文件 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.");
             // 關(guān)閉文件。
             f1.Close();
             Response.Write("Moving file to c:\\tmp <br>");
             // 獲取 C 的根目錄(C:\)中的文件的句柄。
             f2 = fso.GetFile("c:\\testfile.txt");
             // 把文件移動(dòng)到 \tmp 目錄。
             f2.Move ("c:\\tmp\\testfile.txt");
             Response.Write("Copying file to c:\\temp <br>");
             // 把文件復(fù)制到 \temp 目錄。
             f2.Copy ("c:\\temp\\testfile.txt");
             Response.Write("Deleting files <br>");
             // 獲得文件當(dāng)前位置的句柄。
             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 長(zhǎng)春語林科技 閱讀(7017) 評(píng)論(1)  編輯  收藏 所屬分類: js

          FeedBack:
          # re: js 操作文件[未登錄]
          2016-06-19 20:49 | 00

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
          博客園   IT新聞   Chat2DB   C++博客   博問  
           
          <2008年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

           

          長(zhǎng)春語林科技?xì)g迎您!

          常用鏈接

          留言簿(6)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          相冊(cè)

          收藏夾

          搜索

          •  

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 长白| 桑植县| 门源| 景德镇市| 宜兰县| 灵川县| 茌平县| 西华县| 施甸县| 沁源县| 襄城县| 锦屏县| 旅游| 庐江县| 汶上县| 德安县| 平原县| 武城县| 灵石县| 固安县| 周至县| 梅州市| 新乡县| 宣恩县| 体育| 鲜城| 安仁县| 灵寿县| 通海县| 柳河县| 鹿泉市| 商城县| 马龙县| 忻州市| 上思县| 六枝特区| 蒙山县| 中西区| 乡城县| 威信县| 巧家县|