- February 8, 2017
- Posted by: iSummation Team
- Category: Uncategorized
I was having situation where I wanted to read a file and process each line.
I think cffile tag is not capable to do it, so I use java classes.
Basically we need two kinds of classes.
2. Buffer reader
Buffer reader is capable to read any input stream line by line.
Final code will look like:
FileName = expandPath(‘/temp.txt’);
objFileReader = createObject("java","java.io.FileReader");
InputStreamReader = objFileReader.init(FileName);
objBuffer = createObject("java","java.io.BufferedReader" );
LineIO = objBuffer.init(InputStreamReader);
<cfset eof = 0>
<cfset cnt = 1>
<cfloop condition="not eof">
<cfset currline = LineIO.readline()>
<cfif isdefined("currline") eq "no">
<cfset eof = 1>
<cfoutput>line #cnt#: #currline#<br/></cfoutput>
<cfset cnt = cnt + 1>