A few days ago I was going to write something that involved reading files.
But I don’t want to use FSO because I’m afraid some spaces won’t support it.
But after searching for a long time on the Internet, I couldn't find one that was not written in FSO.
Or I made one myself.
I remember that I used stream when doing componentless upload and saving files.
I found that there is a LoadFromFile method. The file can be read.
Below is my code.
function readfile(URL,chartype)
set srmObj = server.CreateObject("adodb.stream")
srmObj.type=1
srmObj.mode=3
srmObj.open
srmObj.Position=0
srmObj.LoadFromFile URL
srmObj.Position = 0
srmObj.type=2
srmObj.charset=chartype
readfile=srmObj.readtext()
end function
has two parameters. URL is the path of the file, it seems that it can only be an absolute path. chartype is the encoding in which the file is stored.
Returns a string containing the contents of the file.
This function can only read text files. Reading binary files is similar. Those who want to use it can change it themselves