0

First I want to create a text file in local system and also add contents to the file, after that I want to open that file.

Can't create file using the code, also want code to open a file from local system. Can any one help me or provide with details that is it possible?

<body>

<input type="button" value="create" onclick="createFile()"/>    
  
 <script type="text/javascript"  language="javascript">

      function createFile()
                    {
                      try{
                            var fso,file;
                            fso=new ActiveXObject("Scripting.FileSystemObject");
                            file=fso.CreateTextFile("D:\\ppp.txt");
                            file.WriteLine("AAAAA");
                            file.close();
                        }
                           catch(err){
                               alert(err.message);
                           }                       
                    }

                  </script>

</body>

While running in IE got the error:

Automation server can't create object

running in Chrome got the error:

ActiveXObject is not defined

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
tijuvj
  • 83
  • 2
  • 10

3 Answers3

0

JavaScript does not have the rights to read/write the users filesystem. You can just use HTML5 localstorage to save data on the client.

Ferdinand Torggler
  • 1,304
  • 10
  • 11
0

have a look at the post if you will read it with a cool mind you will get knowlegde

here

Community
  • 1
  • 1
0

It is not possible in javascript , May be you can try Filesystem API which is currently supported in Chrome and Opera. You can read about it more here: http://www.html5rocks.com/en/tutorials/file/filesystem/

sri85
  • 337
  • 2
  • 19