ColdFusion 9.0 Resources |
FileReadDescriptionReads an on-disk or in-memory text file or a file object created with the FileOpen function. You use this function either as an alternative to the cffile tag with the action="read" attribute. You can also use this function to improve performance when reading a large file, because FileRead does not read the entire file into memory. ReturnsIf you specify a filepath, the full text content of the file. If you specify a file object, the character or byte buffer of the specified size. If the file was opened in read mode, FileRead returns the character data (a string), otherwise it returns binary data. Parameters
UsageYou can read a text file or a file object with the FileRead function. When you specify an absolute path of a text file, ColdFusion reads the entire contents of the file. When you specify a file object, which you created using the FileOpen function, ColdFusion reads the number of characters specified in buffersize. Example<h3>FileRead Example - Reading a file</h3> <!--- This reads and outputs the entire file contents. ---> <cfscript> myfile = FileRead("c:\temp\myfile.txt"); WriteOutput("#myfile#"); </cfscript> <!--- This reads and outputs the first 100 characters ---> <!--- from the same file. ---> <cfscript> myfile = FileOpen("c:\temp\test1.txt", "read"); x = FileRead(myfile, 100); WriteOutput("#x#"); FileClose(myfile); </cfscript> |