AlexisSorbas Absent Member.
Absent Member.
184 views

Read a file as one operation

Hello,

 

I search for an operation to read a file in one step.

 

I found operations "Read from File" and "Read file" in the operations folder, but both operations read a file line by line and this takes time. Also, if you had a look at the output of a flow afterwards, the huge amount of "read steps" confuses a little bit.

 

I tried using a scriptlet and operation "Do nothing", that fixes my above mentioned problems, but then I got the problem, that the output is not encoded as UTF-8.

 

Sample of scriptlet:

scriptletResult = "";
filename = scriptletInput;
inputStream = new java.io.BufferedReader(new java.io.FileReader(filename));
while((line = inputStream.readLine()) != null) {
    scriptletResult = scriptletResult+line+"\r\n";
}

 

Do you have any idea to help me?

 

Regards Alexis

Labels (1)
0 Likes
2 Replies
Absent Member.. Steve_Drummond Absent Member..
Absent Member..

Re: Read a file as one operation

Hi Alex,

 

A little trick I found with Read File which works on both 7.51.x and 9.x .

 

Set the 'delimiter' input to be a blank line but setting it to 'Use Constant' and pressing 'Enter' in the value box; make sure that 'store' input is set to True otherwise you just get a count of matching lines.

 

Point both 'More Lines' and 'No More Lines' responses to your next operation. Give the ReadFile a result inheriting from 'returnResult' result field.

 

Set a new filter on your result; use Regex and set the expression to '\S*' and mode is 'Line by Line'.

 

This will return the entire file to you in one read and strips out the blank lines put in by the 'delimiter' input. If the files you are reading from contain blank lines then you can change the delimiter to be something else, '&&Delim&&' for example and either use regex as before or do a Replace filter to get rid of the delimiter.

 

Hope that helps.

 

cheers

steve

 

0 Likes
jadda Absent Member.
Absent Member.

Re: Read a file as one operation

Hi ,

 

 I would Suggest another operation instead ofusing  Read file  operation.

 

1.For windows execute  Remote command "type filename"

 

2. For Unix  execute remote command  "cat filename"

 

This always resolve the problem. I am using same concept for many flows.

 

 

😄

 

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.