Maple Professionel
Maple Académique
Maple Edition Étudiant
Maple Personal Edition
Maple Player
Maple Player for iPad
MapleSim Professionel
MapleSim Académique
Maple T.A. - Suite d'examens de classement
Maple T.A. MAA Placement Test Suite
Möbius - Didacticiels de mathématiques en ligne
Machine Design / Industrial Automation
Aéronautique
Ingénierie des véhicules
Robotics
Energie
System Simulation and Analysis
Model development for HIL
Modélisation du procédé pour la conception de systèmes de contrôle
Robotics/Motion Control/Mechatronics
Other Application Areas
Enseignement des mathématiques
Enseignement de l’ingénierie
Enseignement secondaire et supérieur (CPGE, BTS)
Tests et évaluations
Etudiants
Modélisation financière
Recherche opérationnelle
Calcul haute performance
Physique
Webinaires en direct
Webinaires enregistrés
Agenda des évènements
Forum MaplePrimes
Blog Maplesoft
Membres Maplesoft
Maple Ambassador Program
MapleCloud
Livres blancs techniques
Bulletin électronique
Livres Maple
Math Matters
Portail des applications
Galerie de modèles MapleSim
Cas d'Etudes Utilisateur
Exploring Engineering Fundamentals
Concepts d’enseignement avec Maple
Centre d’accueil utilisateur Maplesoft
Centre de ressources pour enseignants
Centre d’assistance aux étudiants
fopen - opens a file for buffered reading or writing
Calling Sequence
fopen(name, mode)
fopen(name, mode, type)
Parameters
name
-
the name of the file to be opened
mode
one of READ, WRITE, or APPEND
type
optional, one of TEXT or BINARY
Description
Opens the file with the specified name for buffered reading or writing as specified by mode and returns a file descriptor (a small integer).
In most cases, it is not necessary to fopen a file in order to access it. The first operation performed on a file will open it if it is not already open. The fopen function is provided as a convenience to those porting code written in other languages (such as C) to Maple, and for those cases where it is desirable to override the default file type provided by the I/O functions.
If a type is specified, it indicates whether the file contains TEXT (a stream of characters) or BINARY (a stream of bytes). When opened as type TEXT, newline characters ("\n") are translated to the platform-appropriate representation when writing, and back to newline characters when reading.
If no type is specified, type TEXT is assumed.
On platforms (such as UNIX) where there is no distinction between text and binary files, a type specification is allowed, but superfluous.
The special file names 'default' and 'terminal' (symbols) refer to the current and top-level input or output streams.
If the file being opened is already open, fopen generates an error.
If the file is being opened for reading and does not exist, fopen generates an error.
If the file is being opened for writing and does not exist (and is not already open), it is created, if possible; otherwise, fopen generates an error. If the file does exist (and is not already open), it is truncated. Writing starts at the beginning of the file if WRITE was specified, and at the end of the existing file if APPEND was specified.
If the limit for the maximum number of simultaneously open files has been reached, fopen generates an error.
The number of open files allowed is system specific.
When writing many files, you must fclose() each of them to ensure that you do not run out of file handles.
For information on filenames, see file.
Thread Safety
The fopen command is thread safe as of Maple 15.
Parallel calls to file i/o commands on the same file descriptor will be serialized in an arbitrary order. If you need the commands to execute in a particular order you must use Maple's synchronization tools to enforce this. See Threads:-Mutex.
For more information on thread safety, see index/threadsafe.
Examples
Use of 'terminal' for output
This is a test
Note: fclose cannot be used with the terminal file descriptor
Error, (in fclose) operation not allowed on `terminal` stream
See Also
fclose, file, file_types, IO_errors, open
Download Help Document