文件末尾eof

Files contain different types of data like text, image, video, headers, graphics, etc. All these data are stored in different encoding and formatting techniques but every file has an end which is named End Of File which sets the last by of the given file. In this tutorial, we will learn the meaning of the End Of File and relation with the popular programming languages like C, C++, PHP, Java, Python.

文件包含不同类型的数据,例如文本,图像,视频,标题,图形等。所有这些数据均以不同的编码和格式设置技术存储,但是每个文件都有一个名为End Of File的末尾,该末尾设置了给定的最后一个文件。 在本教程中,我们将学习End Of File的含义以及与流行的编程语言(如C,C ++,PHP,Java,Python)的关系。

什么是文件结尾? (What Is End Of File?)

End Of File is the special data or delimiter which will set the end of file for a specific file. This file contains different types of data from text to image but the end of the file is the same for all of them. End Of File can be also expressed as EOF in a short form. EOF is also used in different programming languages in order to express and check the end of the file.

文件结尾是特殊数据或定界符,它将为特定文件设置文件结尾。 该文件包含从文本到图像的不同类型的数据,但是文件的结尾对于所有这些文件都是相同的。 文件结尾也可以用EOF的短形式表示。 EOF也用在不同的编程语言中,以表示和检查文件的结尾。

Checking the end of the file is important especially developing applications. While reading a file to process, print or view we need to check the end of file in some cases especially in low-level operations.

检查文件结尾很重要,尤其是在开发应用程序时。 在某些情况下,尤其是在低级操作中,在读取文件进行处理,打印或查看时,我们需要检查文件的末尾。

C和C ++中的文件结尾 (End Of File In C and C++)

C and C++ provide different file operation functions. We can use EOF value in order to check the end of the file which can be used to check different functions return value. EOF stores the -1 where a file operation function will return -1 when the end of file is reached.

C和C ++提供了不同的文件操作功能。 我们可以使用EOF值来检查文件的结尾,该文件可以用来检查不同函数的返回值。 EOF存储-1 ,到达文件末尾时文件操作函数将返回-1

In the following example, we will read the file named myfile.txt with the getc() function which will read a single character from a given file for each time. We will check the EOF after every read operation.

在下面的示例中,我们将使用getc()函数读取名为myfile.txt的文件,该函数将每次从给定文件中读取单个字符。 每次读取操作后,我们都会检查EOF。

#include <stdio.h> int main()
{ FILE *fp = fopen("myfile.txt", "r"); int ch = getc(fp);//Check enf of file and if not end execute while block//File EOF reached end while loop while (ch != EOF) { /* Print the file content with ch */putchar(ch); /* Read one character from file */ch = getc(fp); } if (feof(fp)) printf("\n End of file reached."); elseprintf("\n Something went wrong."); fclose(fp); getchar(); return 0;
}

PHP中的文件结尾 (End Of File In PHP)

PHP provides feof() function in order to check the end of the file. When there are some bytes or not end of file the feof() function will return false and the provided iteration will continue till to end of the file.

PHP提供了feof()函数来检查文件的结尾。 当文件末尾有字节或没有字节时,feof()函数将返回false,并且所提供的迭代将持续到文件末尾。

<?php // We will open the myfile.txt and set to variable $check
$check = fopen("myfile.txt", "r"); $seq = fgets($check); // Outputs a line of the file until
// the end-of-file is reached
while(! feof($check))
{
echo $seq ;
$seq = fgets($check);
} // We will close the file with fclose() function
fclose($check); ?>

Java中的文件结尾 (End Of File In Java)

Java programming language provides different functions in order to read, write files. In Java when a file is read the value generally stored in a variable like a String. If the end of the file is reached the returned value will be a null which is simply nothing. We can check the end of the file if the returned value is null like below.

Java编程语言提供了不同的功能以便读取和写入文件。 在Java中,当读取文件时,该值通常存储在诸如String之类的变量中。 如果到达文件的末尾,则返回的值将为null ,即为null 。 我们可以检查文件的结尾是否是返回的null,如下所示。

import java.io.*;
import java.util.*;public class End_Of_File_Example{public static void main(String[] args) {Scanner scanner = new Scanner(System.in);String ab= scanner.nextLine();int a=0;while(ab != null){System.out.printf("%d %s\n",++a,ab);ab=scanner.nextLine();}scanner.close();}
}

Python中的文件结尾 (End Of File In Python)

In Python, there is no specific EOF function but we can use some techniques like checking line we read and determine the EOF. We will read the file line by line with while loop. If the end of the file is reached the returned line value will be null.

在Python中,没有特定的EOF函数,但是我们可以使用一些技术,例如检查读取的行并确定EOF。 我们将通过while循环逐行读取文件。 如果到达文件末尾,则返回的行值将为null。

# We will set the file name we want to read
filename = "myfile.txt" # We open file with open() function to only read
filehandle= open(filename, 'r') while True: #Read single line   line = filehandle.readline() #Check line if it is not null#If line is null this means EOFif not line: break print(line) # Close the file handler
filehandle.close()
.ub438be1892cfce20a0aa65cf5baceb8c , .ub438be1892cfce20a0aa65cf5baceb8c .postImageUrl , .ub438be1892cfce20a0aa65cf5baceb8c .centered-text-area { min-height: 80px; position: relative; } .ub438be1892cfce20a0aa65cf5baceb8c , .ub438be1892cfce20a0aa65cf5baceb8c:hover , .ub438be1892cfce20a0aa65cf5baceb8c:visited , .ub438be1892cfce20a0aa65cf5baceb8c:active { border:0!important; } .ub438be1892cfce20a0aa65cf5baceb8c .clearfix:after { content: ""; display: table; clear: both; } .ub438be1892cfce20a0aa65cf5baceb8c { display: block; transition: background-color 250ms; webkit-transition: background-color 250ms; width: 100%; opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; background-color: #ECF0F1; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -moz-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -o-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); } .ub438be1892cfce20a0aa65cf5baceb8c:active , .ub438be1892cfce20a0aa65cf5baceb8c:hover { opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; background-color: #D35400; } .ub438be1892cfce20a0aa65cf5baceb8c .centered-text-area { width: 100%; position: relative; } .ub438be1892cfce20a0aa65cf5baceb8c .ctaText { border-bottom: 0 solid #fff; color: #3498DB; font-size: 16px; font-weight: bold; margin: 0; padding: 0; text-decoration: underline; } .ub438be1892cfce20a0aa65cf5baceb8c .postTitle { color: #27AE60; font-size: 16px; font-weight: 600; margin: 0; padding: 0; width: 100%; } .ub438be1892cfce20a0aa65cf5baceb8c .ctaButton { background-color: #e6e6e6!important; color: #3498DB; border: none; border-radius: 3px; box-shadow: none; font-size: 14px; font-weight: bold; line-height: 26px; moz-border-radius: 3px; text-align: center; text-decoration: none; text-shadow: none; width: 80px; min-height: 80px; background: url(https://www.poftut.com/wp-content/plugins/intelly-related-posts/assets/images/simple-arrow.png)no-repeat; position: absolute; right: 0; top: 0; } .ub438be1892cfce20a0aa65cf5baceb8c:hover .ctaButton { background-color: #E67E22!important; } .ub438be1892cfce20a0aa65cf5baceb8c .centered-text { display: table; height: 80px; padding-left: 18px; top: 0; } .ub438be1892cfce20a0aa65cf5baceb8c .ub438be1892cfce20a0aa65cf5baceb8c-content { display: table-cell; margin: 0; padding: 0; padding-right: 108px; position: relative; vertical-align: middle; width: 100%; } .ub438be1892cfce20a0aa65cf5baceb8c:after { content: ""; display: block; clear: both; }

LEARN MORE  Multiline Strings in Python

.ub438be1892cfce20a0aa65cf5baceb8c , .ub438be1892cfce20a0aa65cf5baceb8c .postImageUrl , .ub438be1892cfce20a0aa65cf5baceb8c .centered-text-area { min-height: 80px; position: relative; } .ub438be1892cfce20a0aa65cf5baceb8c , .ub438be1892cfce20a0aa65cf5baceb8c:hover , .ub438be1892cfce20a0aa65cf5baceb8c:visited , .ub438be1892cfce20a0aa65cf5baceb8c:active { border:0!important; } .ub438be1892cfce20a0aa65cf5baceb8c .clearfix:after { content: ""; display: table; clear: both; } .ub438be1892cfce20a0aa65cf5baceb8c { display: block; transition: background-color 250ms; webkit-transition: background-color 250ms; width: 100%; opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; background-color: #ECF0F1; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -moz-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -o-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); } .ub438be1892cfce20a0aa65cf5baceb8c:active , .ub438be1892cfce20a0aa65cf5baceb8c:hover { opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; background-color: #D35400; } .ub438be1892cfce20a0aa65cf5baceb8c .centered-text-area { width: 100%; position: relative; } .ub438be1892cfce20a0aa65cf5baceb8c .ctaText { border-bottom: 0 solid #fff; color: #3498DB; font-size: 16px; font-weight: bold; margin: 0; padding: 0; text-decoration: underline; } .ub438be1892cfce20a0aa65cf5baceb8c .postTitle { color: #27AE60; font-size: 16px; font-weight: 600; margin: 0; padding: 0; width: 100%; } .ub438be1892cfce20a0aa65cf5baceb8c .ctaButton { background-color: #e6e6e6!important; color: #3498DB; border: none; border-radius: 3px; box-shadow: none; font-size: 14px; font-weight: bold; line-height: 26px; moz-border-radius: 3px; text-align: center; text-decoration: none; text-shadow: none; width: 80px; min-height: 80px; background: url(https://www.poftut.com/wp-content/plugins/intelly-related-posts/assets/images/simple-arrow.png)no-repeat; position: absolute; right: 0; top: 0; } .ub438be1892cfce20a0aa65cf5baceb8c:hover .ctaButton { background-color: #E67E22!important; } .ub438be1892cfce20a0aa65cf5baceb8c .centered-text { display: table; height: 80px; padding-left: 18px; top: 0; } .ub438be1892cfce20a0aa65cf5baceb8c .ub438be1892cfce20a0aa65cf5baceb8c-content { display: table-cell; margin: 0; padding: 0; padding-right: 108px; position: relative; vertical-align: middle; width: 100%; } .ub438be1892cfce20a0aa65cf5baceb8c:after { content: ""; display: block; clear: both; }

在Python中了解更多多行字符串

翻译自: https://www.poftut.com/what-is-eof-end-of-file-examples-with-php-c-cpp-python-java/

文件末尾eof

文件末尾eof_什么是EOF(文件末尾)? PHP,C ++,C,Python,Java的示例相关推荐

  1. java 对象流判断文件末尾 ( end of file / eof异常处理 )

    文章目录 一. 以集合为对象读写文件 ( 最优解 ) 二. 写入空值作为文件结尾标志, 读到null终止 三. 处理 EOFException 时继续编码 一. 以集合为对象读写文件 ( 最优解 ) ...

  2. java 文件结束符 eof_文件结束符EOF .

    >> 关于文件结束符EOF EOF 是 End Of File 的缩写. 在C语言中,它是在标准库中定义的一个宏. 人们经常误认为EOF 是从文件中读取的一个字符(牢记).其实,EOF 不 ...

  3. 关于EOF(文件结束符)问题的体会

    最近写了些代码,在对文件的操作中发现了很经典的EOF问题,呵呵. EOF,即end of file,文件结尾,作为文件结束的标志,在程序中常作为判断的一个标志.但在我们平常的程序中却常发生意想不到的结 ...

  4. C++ 简单读写文本文件、统计文件的行数、读取文件数据到数组

    转自:http://hi.baidu.com/ctralt/blog/item/cde79fec87f841302697911c.html fstream提供了三个类,用来实现c++对文件的操作.(文 ...

  5. C语言 复制文件内容粘贴到另一个文件中

    #include <stdio.h>int main(void){int ch;FILE *sfp;FILE *dfp;char sname[FILENAME_MAX];char dnam ...

  6. python对文件的操作模式_python对文件的操作

    一.python中对文件.文件夹操作时经常用到的os模块和shutil模块常用方法. 1.得到当前工作目录,即当前Python脚本工作的目录路径: os.getcwd() 2.返回指定目录下的所有文件 ...

  7. c语言中 文件的字符串输入函数是6,【C语言】文件操作及输入输出格式(文件常用的库函数)...

    参考中国大学MOOC 浙江大学翁恺C语言程序设计在线课程 目录 常用文件输入输出符号格式及标准 常用应用对象为文件的库函数简介: 库函数部分: 文件创建.打开.阅读: 数据块写入读出(只有这两个函数可 ...

  8. php打开文件读写函数,php中常用文件操作读写函数介绍

    本文章介绍了下面几个常用的文件操作函数 file_get_contents 读取整个文件内容 fopen 创建和打开文件 fclose 关闭文件 fgets 读取文件一行内容 file_exists ...

  9. php文件读取文件内容,PHP文件系统函数-读取文件内容几种方式

    介绍几种php获取文件内容的方式 介绍读取文件的方式之前,我们先看一下打开文件资源和关闭资源 名字资源绑定到一个流 - fopen 关闭一个已打开的文件指针 - fclose $handle1 = f ...

最新文章

  1. 对PostgreSQL缺省表空间的理解
  2. Inversion Sequence(csu 1555)
  3. SQL Select语句完整的执行顺序:
  4. 最小生成树之Kruskal算法
  5. 【控制】第九章-线性系统的状态空间描述
  6. Linux基本命令之文件查找、检索
  7. java集合浅谈(一)
  8. 动态规划训练16 [Doing Homework HDU - 1074 ]
  9. 我算是优秀的程序员吗?
  10. 怎么用python编程前二n-1项的等差数列的和_python 等差数列末项计算方式
  11. 由于已明确禁止所请求的页类型,无法对该类型的页提供服务。扩展名“.asp”可能不正确 asp网页在vs中的调试
  12. (第十章)多表查询之in,exitst
  13. Electron 遭封杀,Web 开发者在苹果平台上举步维艰!
  14. 安全运维 - Linux系统攻击回溯
  15. 左撇子的成长指南:我是左撇子.TXT
  16. 计算机硬件系统的五大组成部分是什么,硬件系统的五大组成部分
  17. cad缩放_CAD常见问题详解,解决你当前的烦恼
  18. 一个虚拟摄像头Filter(Virtual Cam Capture Filter)
  19. linux终端界面美化,Ubuntu 18.04系统美化记录:Grub2\主题\登录界面\终端美化
  20. 星起航:抖音小店适合去做吗

热门文章

  1. java.lang.IllegalArgumentException: Name for argument type [java.lang.Integer] not available异常
  2. 【自学宝典】从零开始自学网络安全,按照这个路线就可以了
  3. VS2012编译和调用gdal
  4. 【07】QQ群管理公告小结:
  5. 数学模型之整数规划(0-1规划)
  6. 清华计算机系残疾学生,清华学霸矣晓沅:拖拽着残疾的身体,追求生命的完美...
  7. JQuery18(JQ原理 DOM元素 appendTo append prepend prependTo InsertBefore Before JReplaceAll)
  8. python实现次梯度(subgradient)和近端梯度下降法 (proximal gradient descent)方法求解L1正则化
  9. Qt制作漂亮个性化的界面
  10. JS 的 _.isEmpty()函数使用