File Operations in Mule 4 | Read-Write File in Mule 4

File operations in Mule 4



1. Move: Move is used to move file from one location to another.

Flow:


Move component configuration:


2. Write: Write is used to write content in file.

Flow:
List component is used to read the file, path of file to be read is mentioned in List component settings.
Path of output file is mentioned in write component settings.

3. Delete: Delete is used to delete a file.

Flow:

Path of the file to be deleted is mentioned in delete component settings.

4. Create Directory: It create directory in the path specified.
Flow:

Path where directory needs to be created is mentioned in create directory settings.

5. Copy: It is used to copy file from one location to another.

Flow:

Copy component configurations:


XML Project code:

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:file="http://www.mulesoft.org/schema/mule/file"
     xmlns="http://www.mulesoft.org/schema/mule/core"
     xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
     <http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="64c1cb79-9451-4a2b-9b9a-cc9b347cf5fb" >
          <http:listener-connection host="0.0.0.0" port="8085" />
     </http:listener-config>
     <file:config name="File_Config" doc:name="File Config" doc:id="2af975d8-be58-47de-9bdc-83fa1757b4da" >
          <file:connection workingDir="C:\AnypointStudio\studio-workspace\test_file\src\test\resources" />
     </file:config>
     <file:config name="File_Config1" doc:name="File Config" doc:id="b1567451-49be-46a2-b012-7b72e2d52800" >
          <file:connection workingDir="C:\AnypointStudio\studio-workspace\test_file\src\main\resources\output" />
     </file:config>
     <flow name="test_fileFlow" doc:id="fc3b46bf-0539-4bf6-8699-704573d584ff" >
          <http:listener doc:name="Listener" doc:id="e0f27a16-e86f-498c-a835-4ef315dbf36e" config-ref="HTTP_Listener_config" path="/move"/>
          <file:move doc:name="Move" doc:id="e527a3b8-94f3-4f81-8e4c-685e550f6057" sourcePath="C:\Users\Raveena\AnypointStudio\studio-workspace\test_file\src\main\resources\file.txt" targetPath="C:\Users\Raveena\AnypointStudio\studio-workspace\test_file\src\test\resources"/>
     </flow>
     <flow name="test_fileFlow1" doc:id="0c73b438-24b1-475f-b3b6-5d6f32ea94e7" >
          <http:listener doc:name="Listener" doc:id="3421702e-7171-4a5e-887c-bc5f8494b528" config-ref="HTTP_Listener_config" path="/list"/>
          <file:list doc:name="List" doc:id="77552934-7a56-4cf0-bc2a-dba53fe01207" directoryPath="C:\AnypointStudio\studio-workspace\test_file\src\main\resources\input" config-ref="File_Config"/>
          <foreach doc:name="For Each" doc:id="118cdb9f-31b1-4ee1-9ba1-2f01934d4611" >
              <file:write doc:name="Write" doc:id="706ec9ea-facb-45fb-b7d0-e7d36a285a7d" path="C:\AnypointStudio\studio-workspace\test_file\src\main\resources\output\filess.txt" config-ref="File_Config1"/>
          </foreach>
     </flow>
     <flow name="test_fileFlow2" doc:id="13e4661f-7e61-470d-915b-764bf5d0c334" >
          <http:listener doc:name="Listener" doc:id="0032db84-d846-4a40-9f67-071cc129c34d" config-ref="HTTP_Listener_config" path="/delete"/>
          <file:delete doc:name="Delete" doc:id="bb60554c-293c-42c7-8dd3-44774a88ef1a" config-ref="File_Config" path="C:\AnypointStudio\studio-workspace\test_file\src\main\resources\output"/>
     </flow>
     <flow name="test_fileFlow3" doc:id="83013566-f62d-4c78-9a36-fae07350dada" >
          <http:listener doc:name="Listener" doc:id="56a64cdd-5d0b-4320-b95c-a31a0edbf7d5" config-ref="HTTP_Listener_config" path="/dir"/>
          <file:create-directory doc:name="Create directory" doc:id="8e7adc75-bc4a-4ea6-97bf-7f7425e5b30d" config-ref="File_Config" directoryPath="C:\AnypointStudio\studio-workspace\test_file\src\main\resources\other"/>
     </flow>
     <flow name="test_fileFlow4" doc:id="6cd57805-58c0-4b88-baf9-39a510f3790d" >
          <http:listener doc:name="Listener" doc:id="817dd569-dce0-4eb0-aeb0-72f592559548" config-ref="HTTP_Listener_config" path="/copy"/>
          <file:copy doc:name="Copy" doc:id="30eaf427-c64b-4108-9b38-76a6facd9d59" sourcePath="C:\AnypointStudio\studio-workspace\test_file\src\main\resources\input" targetPath="C:\AnypointStudio\studio-workspace\test_file\src\main\resources\other"/>
     </flow>
</mule>


© 2020 goformule.com

Share on :

Mule 4:

XML to JSON in mule 4 Web service consumer VM Validation in Mule 4 Until Successful
Sub flow Set Variable & Remove Variable Set Transaction ID Scatter Gather Round Robin
Consume Restful Service CRUD in Mule 4 Parse Template Object to JSON Load Static Resource
JSON to XML Invoke Idempotent Filter ForEach Flat file to JSON
Fixwidth to JSON First Successful File Execute Error Handling
Email Dynamic Evaluate Custom Business Event CSV to JSON Copybook to JSON
Choice Router Async RabbitMQ


Mule 3:


Database Connector Async CXF Attachement XSLT
Mongo DB Cache scope Custom Business Event Gzip Compress Expression
SMTP For Each Expression Javascript Filter Reference
Salesforce Message Enricher Groovy Parse Template Idempotent
VM Poll Invoke Ruby Message
Webservice consumer Python Transformer reference Message Property Not
Collection Aggregator First Sucessful Catch Exception Strategy Reference Exception Strategy Or
Choice Message Chunk Aggregator Choice Exception Strategy Global Exception Strategy Schema Validation
Custom Aggregator Scatter Gather Custom Exception Strategy Batch Processing MEL
M Unit RAML Map Operator API Mocking Dataweave