by the operating system to maintain the context
by the operating system to maintain the context of the opened file. Among other things it stores the current data pointer, which gets incremented after read or write calls. The returned file handle should be referred to in all the subsequent file related functions. The following code opens the binary file C:tempjob.jpgfor reading: if (!($fp=fopen(”c:/temp/job.jpg”, “rb”))) { printf(”Could not open file job.jpg”); } Closing Files int fclose(int fp) The fclose()function is used to close an opened file. The argument fp is the file pointer of the file to be closed. This function returns true on success or falseon failure. It is important to close an open file when you have finished reading or writing it, to free it for access by other scripts or programs. There are operating system specific limits on the number of files that can remain open at any time. Displaying Files int fpassthru(int fp) The contents of an opened file can be sent to the browser using the fpassthru()function. This function reads the content of the file from the current position in the open file to the end of the file, and writes it to the standard output. The argument fp is the file pointer of the open file. This function returns true on success, falseon failure. If the opened file is a binary file, then open the file using bflag. Otherwise the browser will not be able to render the file properly. The readfile() method can also be used to send the contents of the file to the browser, but use fpassthru() to send the contents of a binary file. The following code sends the contents of the binary file C:tempjob.jpgto the browser: if (!($fp=fopen(”c:/temp/job.jpg”, “rb”))) { printf(”Could not open file job.jpg”); } else { fpassthru($fp); } int readfile(string filename) The readfile() method takes the file name as an argument. This method assumes the file is a text file. It returns true on success and falseon failure. Reading from Files string fread(int fp, int length) The fread()function can be used to read a string from the open file. The fread()function returns a string of up to length characters from the file with the pointer fp. If the end of the file is reached before the specified length, then the text up to that point is returned. As a side effect of this call the current position of the file pointer is changed to the next unread character Page 238
Note: If you are looking for top 10 and very good webhost to host and run your jsp application check Actions jsp hosting services