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
-
I think it is not possible.Praveen– Praveen2013年08月02日 10:59:35 +00:00Commented Aug 2, 2013 at 10:59
-
possible duplicate of Is it possible to access local file via javascript?rene– rene2013年08月02日 11:00:42 +00:00Commented Aug 2, 2013 at 11:00
-
Why your are not using Node.js library. It designed for that purpose only.naresh kumar– naresh kumar2013年08月02日 11:03:02 +00:00Commented Aug 2, 2013 at 11:03
3 Answers 3
JavaScript does not have the rights to read/write the users filesystem. You can just use HTML5 localstorage to save data on the client.
Comments
have a look at the post if you will read it with a cool mind you will get knowlegde
Comments
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/