Skip to content

Instantly share code, notes, and snippets.

@bennadel
Created March 24, 2014 23:39
Java Exploration in ColdFusion: java.io.LineNumberReader
<!--- Create the line reader. --->
<cfset objLineReader = CreateObject(
"java",
"java.io.LineNumberReader"
).Init(
<!--- Buffered Reader. --->
CreateObject(
"java",
"java.io.BufferedReader"
).Init(
<!--- File reader. --->
CreateObject(
"java",
"java.io.FileReader"
).Init(
<!--- File path. --->
JavaCast( "string", ExpandPath( "./data.txt" ) )
)
)
) />
<!--- Get first line. --->
<cfset REQUEST.LineData = objLineReader.ReadLine() />
<!--- Loop while we still have line data. --->
<cfloop condition="StructKeyExists( REQUEST, 'LineData' )">
<!--- Get the line number. --->
<cfset intLineNumber = objLineReader.GetLineNumber() />
<!--- Output line data. --->
#intLineNumber#) #REQUEST.LineData#<br />
<!--- Read the next line. --->
<cfset REQUEST.LineData = objLineReader.ReadLine() />
</cfloop>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment