Writes on the indicated file in first argument the data of the stream indicated in the second argument. If the file does not exist, it is created with the content indicated in this function. If the file exist, it can be indicated explicitly using the attribute append which you want to add the text because if it is not indicated, the content of the file will become the text indicated in this function (by default, the content is not added, it is replaced).
 

1 file.bytes.write

<file.bytes.write
    append='true|false'
    encoding='encoding'
>
    <file /> +
    <texto /> +
</file.bytes.write>

Exceptions

requires 2 arguments, received: [...]

The correct number of arguments has not been specified.

java.io.FileNotFoundException: ... (The system cannot found the specified path).

The indicated path of the file does not exist. If the field does not exist, the function will create it, but at least the location must exist.

Example

Establish the content of a file.

Copy
<xsql-script name='file_write'>
    <body>
        <set name='m_file'>
            <string>c:<file.separator />tmp<file.separator />deister.txt</string>
        </set>
        <file.bytes.write>
            <file name='#m_file' type='absolute' />
            <string.getBytes>texto del fichero</string.getBytes>
        </file.bytes.write>
    </body>
</xsql-script>
Example

Add content to a file. In this case, if the same file is used as in the previous example, the content would be:

Copy
<xsql-script name='file_write'>
   <body>
       <set name='m_file'>
           <string>c:<file.separator />tmp<file.separator />deister.txt</string>
       </set>

<!--
The file will consist of this two lines:

text of the file
text to add
-->


       <file.bytes.write>
           <file name='#m_file' type='absolute' />
           <string>text of the file</string>
       </file.bytes.write>
       <file.bytes.write append='true'>
           <file name='#m_file' type='absolute' />
           <string.getBytes>text to add</string.getBytes>
       </file.bytes.write>
   </body>

</xsql-script>
Example

Write a file with the wished encoding.

Copy
<xsql-script name='file_write_sample3'>
   <body>
       <set name='m_source_file'>
           <string>c:<file.separator />tmp<file.separator />source.txt</string>
       </set>

<!-- Origin data file with UTF-8 encoding -->


       <set name='m_text' type='string'>
           <object.2string>
               <file.bytes.read>
                   <file name='#m_source_file' type='absolute' />
               <file.bytes.read>
           </object.2string>
       </set>

       <set name='m_dest_file'>
           <string>c:<file.separator />tmp<file.separator />destination.txt</string>
       </set>

       <file.bytes.write append='true' encoding-src='UTF-8' encoding-dst='UTF-8'>
           <file name='#m_dest_file' type='absolute' />
           <m_text/>
       </file.bytes.write>

   </body>

</xsql-script>