11.07.2015 Views

Advanced Programming Guide

Advanced Programming Guide

Advanced Programming Guide

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

f := fopen("testFile.txt",WRITE):> writeline(f,"This is a test"):> fclose(f);4.4 File Manipulation Commands • 165> writeline(f,"This is another test"):Error, (in fprintf) file descriptor not in useWhen you exit Maple or issue a restart command, Maple automaticallycloses any open files, whether you opened them explicitly by using fopenor open, or implicitly through a file I/O command.Position Determination and AdjustmentAssociated with each open file is the concept of its current position. Thisis the location within the file to which a subsequent write occurs, orfrom which a subsequent read occurs. Any reading or writing operationadvances the position by the number of bytes read or written.You can determine the current position within a file by using thefilepos command. Use this command in the following manner.filepos( fileIdentifier, position )The fileIdentifier is the name or descriptor of the file whose positionto determine or adjust. If you give a filename, and that file is not yetopen, Maple opens it in READ mode with type BINARY.The position is optional. If you do not specify the position, Maplereturns the current position. If you supply the position, Maple sets thecurrent position to your specifications and returns the resulting position.In that case, the returned position is the same as the specified positionunless the file is shorter than the specified position, in which case thereturned position is that of the end of the file (that is, its length). Youcan specify the position either as an integer or as the name infinity,which specifies the end of the file.The following command returns the length of the file myfile.txt.> filepos("myfile.txt", infinity);36

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!