Skip to content

Routes: File Reader

TekMonks edited this page Mar 13, 2019 · 2 revisions

The File Reader Route

The File Reader route node is used to read files. The file reader node reads the entire file and transforms it into a single JSON message.

This node does not parse the parse the file itself and no assumptions are made about the file data format. The property message.content contains the read data.

The code block below documents the format for the File Reader route node.

"route0":{
	"type": "filereader",
	"dependencies":["listener"],
	"path":"c:/test/in/myfile.txt",
        "donePath":"c:/test/done",
        "encoding":"utf8"
}

The path property is used to point to the file to read.

The file reader can be used in conjunction with the file listener node, in which case filepath property is not needed as the the file listener passes the file path to the file reader.

The donePath is the filesystem path to move the CSV file to, once the ASB has finished reading it.

The following code block shows the file reader and file listener being used together to transform an XML file to a JSON file.

{
	"flow":{
		"name":"XML to JSON",
		"disabled":false
	},
	"listener": {
		"type":"file", 
		"isMessageGenerator": true,
		"path":"c:/test/in/Test.xml",
		"donePath":"c:/test/processing"
	},
	"route0":{
		"type": "filereader",
		"dependencies":["listener"],
		"donePath":"c:/test/done",
		"encoding":"utf8"
	},
	"route1": {
		"type":"xmlparser",
		"dependencies":["route0"]
	},
	"output": {
		"type": "filewriter",
		"dependencies":"route1",
		"path":"c:/test/Test.json",
		"prettyJSON": 4,
		"append": false,
		"writeCloseTimeout": 5000
	}
}