473,320 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

writing a text to file in local system using chrome?

Expand|Select|Wrap|Line Numbers
  1. function writeToFile(filename, data) {
  2.    try {
  3.       netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  4.    } catch (e) {
  5.       alert("Permission to save file was denied.");
  6.    }
  7.    var file = Components.classes["@mozilla.org/file/local;1"]
  8.       .createInstance(Components.interfaces.nsILocalFile);
  9.    file.initWithPath( filename );
  10.    if ( file.exists() == false ) {
  11.       //alert( "Creating file... " );
  12.       file.create( Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 420 );
  13.    }
  14.    var outputStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
  15.       .createInstance( Components.interfaces.nsIFileOutputStream );
  16.  
  17.    // Open flags 
  18.    var PR_RDONLY  =     0x01
  19.    var PR_WRONLY  =     0x02
  20.    var PR_RDWR    =     0x04
  21.    var PR_CREATE_FILE = 0x08
  22.    var PR_APPEND  =     0x10
  23.    var PR_TRUNCATE=     0x20
  24.    var PR_SYNC    =     0x40
  25.    var PR_EXCL    =     0x80
  26.  
  27.     outputStream.init( file, PR_RDWR | PR_CREATE_FILE | PR_APPEND, 420, 0 );
  28.    var result = outputStream.write( data, data.length );
  29.    outputStream.close();
  30. }
  31.  
plz help me out.
Nov 28 '11 #1

✓ answered by gits

i'm not aware of a possibility in chrome(-ium) to do that besides when you are writing extensions for the browser.

i would rather check the requirements and try to find a better solution then trying to write a file to the fs. you cannot rely on this since the user always can forbid to do that - and that is for good reasons. if cookies are to small for you you might even try the HTML 5 local storage object.

kind regards

3 4797
Iam capable of writing a text to file in local system using firefox and how to do it same in chrome?
Expand|Select|Wrap|Line Numbers
  1. function writeToFile(filename, data) {
  2.    try {
  3.       netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  4.    } catch (e) {
  5.       alert("Permission to save file was denied.");
  6.    }
  7.    var file = Components.classes["@mozilla.org/file/local;1"]
  8.       .createInstance(Components.interfaces.nsILocalFile);
  9.    file.initWithPath( filename );
  10.    if ( file.exists() == false ) {
  11.       //alert( "Creating file... " );
  12.       file.create( Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 420 );
  13.    }
  14.    var outputStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
  15.       .createInstance( Components.interfaces.nsIFileOutputStream );
  16.  
  17.    // Open flags 
  18.    var PR_RDONLY  =     0x01
  19.    var PR_WRONLY  =     0x02
  20.    var PR_RDWR    =     0x04
  21.    var PR_CREATE_FILE = 0x08
  22.    var PR_APPEND  =     0x10
  23.    var PR_TRUNCATE=     0x20
  24.    var PR_SYNC    =     0x40
  25.    var PR_EXCL    =     0x80
  26.  
  27.     outputStream.init( file, PR_RDWR | PR_CREATE_FILE | PR_APPEND, 420, 0 );
  28.    var result = outputStream.write( data, data.length );
  29.    outputStream.close();
  30. }
plz help me out?
Nov 30 '11 #2
gits
5,390 Expert Mod 4TB
i'm not aware of a possibility in chrome(-ium) to do that besides when you are writing extensions for the browser.

i would rather check the requirements and try to find a better solution then trying to write a file to the fs. you cannot rely on this since the user always can forbid to do that - and that is for good reasons. if cookies are to small for you you might even try the HTML 5 local storage object.

kind regards
Nov 30 '11 #3
Thanks for replay even am trying for the same but some article says that in chrome its possible so..
Dec 1 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Rob Meade | last post by:
Hi all, Ok - minor fly in my ointment... I have an application which was successfully writing data from submitted forms to a text file in a directory - in this case: /data/findata.txt ...
0
by: Andrius | last post by:
Hello, having some problems by writing XML file by XML schema. using strongly typed datasets. Schema: <?xml version="1.0" ?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">...
13
by: Chris Johnson | last post by:
I have what seems to be such a simple thing yet I cannot figure out how to do it. I am using a streamwriter to build a text file. At the end of the process I want to open that same text file in...
0
by: Samiran Samanta | last post by:
Hi Friends, Can anyone please tell me how to save a text file as a .html and .hhc file using VB.NET. Also it will be helpfull if anyone can point me how to write in a .hhc file using VB.NET. ...
5
by: chisty | last post by:
can any one tell how to write a text file inputs to different edit boxes using a button.....text file contain different data.displaying each data in different edit boxes using single button click
5
by: naamala | last post by:
Hi, How can i get unused/available port in the local system using C# ? Or Is there any way to find out whether the particular port number is being used by any other application using C#? ...
1
by: jitupatil2007 | last post by:
hi friends can anyone suggest me any method or function in C#.Net for moving a whole string from one text file to another text file. or moving a statement from one text file to another text file.....
2
by: meetu3181 | last post by:
Hi All, I am new to perl.I need to parse a text file in unix which is having data like this .I need to to store each value in a seperate variable. The TXT FILE TO BE PARSED: HTTP_PORT = 7779...
0
by: waqasahmd | last post by:
Hi I am using FAXCOMLib to send fax. Now I created a string which is the text to be printed. This text string contains some hard code values, some values from db.. I can send a simple plain...
21
Mas Juliza Alias
by: Mas Juliza Alias | last post by:
Hi, I am building a program on Information System for Reservoir Operation for my Masters research. Now I have a text file which is an output file from a processing software (Terramodel) that lists...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.