• fopen中的mode(20161115)


    mode

    mode 参数指定了所要求到该流的访问类型。可以是以下:

    fopen() 中 mode 的可能值列表

    mode

    说明

    'r'

    只读方式打开,将文件指针指向文件头。

    'r+'

    读写方式打开,将文件指针指向文件头。 (就是覆盖)

    'w'

    写入方式打开,将文件指针指向文件头并将文件大小截为零。(就是在将文件指针指向文件头的同时把文件清空了)如果文件不存在则尝试创建之。

    'w+'

    读写方式打开,将文件指针指向文件头并将文件大小截为零。如果文件不存在则尝试创建之。

    'a'

    写入方式打开,将文件指针指向文件末尾。如果文件不存在则尝试创建之。(相当于追加)

    'a+'

    读写方式打开,将文件指针指向文件末尾。如果文件不存在则尝试创建之。

    'x'

    创建并以写入方式打开,将文件指针指向文件头。如果文件已存在,则 fopen() 调用失败并返回 FALSE ,并生成一条 E_WARNING 级别的错误信息。如果文件不存在则尝试创建之。这和给 底层的 open(2) 系统调用指定 O_EXCL|O_CREAT 标记是等价的。

    'x+'

    创建并以读写方式打开,其他的行为和 'x' 一样。

    'c'

    Open the file for writing only. If the file does not exist, it is created. If it exists, it is neither truncated (as opposed to 'w'), nor the call to this function fails (as is the case with 'x'). The file pointer is positioned on the beginning of the file. This may be useful if it's desired to get an advisory lock (see flock() ) before attempting to modify the file, as using 'w' could truncate the file before the lock was obtained (if truncation is desired, ftruncate() can be used after the lock is requested).

     

    如果调用失败就把文件锁定直到修改文件。

     

    打开仅用于写入的文件。如果该文件不存在,则创建它。如果它存在,它既不被截断(而不是“W”),也没有调用这个函数失败(因为是“X”)。文件指针位于文件的开始位置。这可能是有用的如果是希望得到一个咨询锁(见flock())在试图修改文件,使用“W”可以截断文件之前得到锁(如果需要ftruncate()截断,即可使用请求的锁)。

    'c+'

    Open the file for reading and writing; otherwise it has the

    same behavior as 'c'.

  • 相关阅读:
    python 开启多进程的两种方法
    Python
    Python
    路由器配置
    python 自定义报头 实现大文件传输
    python socket
    Spring MVC 实现文件的上传
    SpringMVC异常处理
    SpringMVC 返回值类型,参数传递 解决乱码
    Spring—MVC案例
  • 原文地址:https://www.cnblogs.com/zsczsc/p/6120293.html
Copyright © 2020-2023  润新知