<!--- Test the Java FileOuptputStream methodology of writing data to disk as we get it, not just at the end. ---> <cftimer label="FileOutputStream Test" type="outline"> <!--- Kill extra output. We want to do this because otherwise, we are creating [intIterations] amount of white space on the page. No need for that. ---> <cfsilent> <!--- Get the file name to write to. ---> <cfset strFilePath = ExpandPath( "./io_output.txt" ) /> <!--- Create the file output stream. When creating the file output stream, we have to initialize it with a Java File object (which we initialize with the path to the file we want to create). ---> <cfset osOutput = CreateObject( "java", "java.io.FileOutputStream" ).Init( CreateObject( "java", "java.io.File" ).Init( strFilePath ) ) /> <!--- Loop over the iterations to build up the data. For each iteration, we are going to select a random string and write that string directly to the output stream which should write it directly to file. ---> <cfloop index="intI" from="1" to="#intIterations#" step="1"> <!--- Add a random string to the file output stream. In this case, the Write() method of the output stream takes a Byte Array. For that, we can call the GetBytes() Java method on the string. We use the ToString() method to create a string object before getting the byte array. ---> <cfset osOutput.Write( ToString( "I am crazy about " & arrParts[ RandRange( 1, 7 ) ] & Chr( 13) & Chr( 10 ) ).GetBytes() ) /> </cfloop> </cfsilent> <!--- Output name of file. ---> #strFilePath# </cftimer>