关键词搜索

源码搜索 ×
×

js读写本地文件js读写本地文件

发布2020-08-26浏览2628次

详情内容

  1. 1. <script language="javascript" type="text/javascript">
  2. 2. /*
  3. 3. object.OpenTextFile(filename[, iomode[, create[, format]]])
  4. 4. 参数
  5. 5. object
  6. 6. 必选项。object 应为 FileSystemObject 的名称。
  7. 7. filename
  8. 8. 必选项。指明要打开文件的字符串表达式。
  9. 9. iomode
  10. 10. 可选项。可以是三个常数之一:ForReading 、 ForWriting 或 ForAppending 。
  11. 11. create
  12. 12. 可选项。Boolean 值,指明当指定的 filename 不存在时是否创建新文件。如果创建新文件则值为 True ,如果不创建则为 False 。如果忽略,则不创建新文件。
  13. 13. format
  14. 14. 可选项。使用三态值中的一个来指明打开文件的格式。如果忽略,那么文件将以 ASCII 格式打开。
  15. 15. 设置
  16. 16. iomode 参数可以是下列设置中的任一种:
  17. 17. 常数 值 描述
  18. 18. ForReading 1 以只读方式打开文件。不能写这个文件。
  19. 19. ForWriting 2 以写方式打开文件
  20. 20. ForAppending 8 打开文件并从文件末尾开始写。
  21. 21.
  22. 22. format 参数可以是下列设置中的任一种:
  23. 23. 值 描述
  24. 24. TristateTrue 以 Unicode 格式打开文件。
  25. 25. TristateFalse 以 ASCII 格式打开文件。
  26. 26. TristateUseDefault 使用系统默认值打开文件。
  27. 27. */
  28. 28.
  29. 29. //读文件
  30. 30. function readFile(filename){
  31. 31. var fso = new ActiveXObject("Scripting.FileSystemObject");
  32. 32. var f = fso.OpenTextFile(filename,1);
  33. 33. var s = "";
  34. 34. while (!f.AtEndOfStream)
  35. 35. s += f.ReadLine()+"\n";
  36. 36. f.Close();
  37. 37. return s;
  38. 38. }
  39. 39.
  40. 40. //写文件
  41. 41. function writeFile(filename,filecontent){
  42. 42. var fso, f, s ;
  43. 43. fso = new ActiveXObject("Scripting.FileSystemObject");
  44. 44. f = fso.OpenTextFile(filename,8,true);
  45. 45. f.WriteLine(filecontent);
  46. 46. f.Close();
  47. 47. alert('ok');
  48. 48. }
  49. 49.
  50. 50. </script>
  51. 51. <html>
  52. 52. <input type="text" id="in" name="in" />
  53. 53. <input type="button" value="Write!" onclick="writeFile('c:/12.txt',document.getElementById('in').value);"/><br><br>
  54. 54. <input type="button" value="Read!" onclick="document.getElementById("__content").value=readFile('http://sc.stock.cnfol.com/090917/123,1282,6534044,00.shtml');"/><br>
  55. 55. <textarea id="show" name="show" cols="100" rows="https://cdn.jxasp.com:9143/image/20" >
  56. 56. </textarea>
  57. 57. </html>

 

相关技术文章

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载