- 1). Right-click the HTML file you want to use to open the file and select "Open With." Click your preferred JavaScript or HTML editor in the list of programs.
- 2). Open the file. The following code opens the file and assigns the file handler to the "file" variable:
file = fopen("filename.txt", 0);
Replace "filename.txt" with the name of your file. - 3). Read the file's content and assign the content to a string variable, in this case, the "content" variable:
length = flength(file);
content = fread(file, length); - 4). Close the file. After you finish reading the file content, you must close the handler.
fclose(file);
SHARE