Code archives/File Utilities/ReadFileAsString$()

This code has been declared by its author to be Public Domain code.

Download source code

ReadFileAsString$() by Difference2003
Read a file into a string, fast.
Function ReadFileAsString$(file$)

	Local tmp$=SystemProperty ("tempdir") + MilliSecs() + "bbrsrf.tmp"
	Local ret$
	Local fbank=CreateBank(	FileSize(file$))

	f=OpenFile (file$)
		If Not f FreeBank fbank : Return ""
	
		ReadBytes fbank,f,0,BankSize(fbank)  	
	CloseFile f
	
	f=WriteFile (tmp$)
		If Not f FreeBank fbank : Return ""
		WriteInt f,BankSize(fbank) 
		WriteBytes fbank,f,0,BankSize(fbank)
	CloseFile f

	f=OpenFile(tmp$)
		If Not f FreeBank fbank : Return ""
		ret$=ReadString(f)
	CloseFile f

	FreeBank fbank

	DeleteFile tmp$

	Return ret$

End Function

Comments

None.

Code Archives Forum