3 Replies Latest reply on Nov 11, 2009 5:55 AM by Bob Stucky

    Write File

    S.Biancardo Level 1

      Hi how can i write a text file?

      I have try this function but not functionaly.

       

      function _error( error )
      {
          var file = File('ERROR/log_error.log');
          if (file.exists)
          {
              file.open();
              file.writeln (error);
              file.close();
          }
      }

        • 1. Re: Write File
          Bob Stucky Adobe Employee


          The most basic:

           

          function _error( error ) {

            var file = new File( "error/log_error.log" );

          file.open( "w" );

          file.writeln( error.toString() );

          file.close();

          }

           

           

          To me it's better to set the entire file path, and make sure that path exists:

           

          var file = new File( Folder.myDocuments.absoluteURI + "/error/log_error.log" );

          if ( !file.parent.exists ) {

             file.parent.create();

          }

           

          Bob

          1 person found this helpful
          • 2. Re: Write File
            S.Biancardo Level 1

            Thanks and if i want to append text to file ?

            I have try open("a") and open("w+") but not functionaly

            • 3. Re: Write File
              Bob Stucky Adobe Employee

              file.open("a");

               

              is in the documentation for "append"

               

              If that's not working, try

               

              file.open( "e" );

              file.seek( 0, 2 ); // file position zero starting from the file

               

               

              Bob