文件末尾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. Kernel 社区 开发准备工作mutt 邮件使用
  2. 罗德里格斯公式推导,以及如何使用cv2.Rodrigues进行旋转矩阵和旋转向量之间的相互转化
  3. [moka同学笔记]redis练习Demo
  4. 第二讲 ODE欧拉数值方法
  5. 计算机统计字符数,如何在Word中统计相同字符(文字)出现的个数 -电脑资料
  6. php计算时间顺延3分,PHP关于strtotime函数的大坑
  7. mybatis应用(三)优化
  8. spring AOP 之一:spring AOP功能介绍
  9. 并发编程-Atomic的compareAndSet
  10. 云效 > 产品简介 > 产品概述
  11. 必备9种能力、9种手段、9种心态
  12. Java-控制台打印万年历代码
  13. luma3ds7.1按start键开机无法启动payload解决
  14. bat计算机清理原理,电脑清理系统垃圾bat的操作步骤
  15. 微型计算机必须具备的输入设备,一台微型计算机必须具备的输出设备是显示器。...
  16. python pyecharts 数据可视化 饼状图绘制
  17. wpf中界面获取鼠标或键盘操作
  18. Java EE之FreeMarker前度模板引擎的使用
  19. 使用torchvision 中的roi_pool/roi_align函数时报错
  20. P1002 过河卒(dp动态规划,洛谷,java)

热门文章

  1. openlayers3中geowebcache的使用
  2. 异地恋的自愈系小故事:企鹅先生和北极熊小姐
  3. MySQl 实现 FULL JOIN
  4. 一个程序员的奋斗历程
  5. 数据库操作银行管理系统
  6. 计算机如何取消左缩进,Word中怎么去掉表格的缩进
  7. vue中 ECharts 图表使用教程
  8. CSAPP lab2 经典的bomblab二次学习
  9. Qt Creator 使用 QMediaPlayer 播放音频无声音
  10. 软件测试学习笔记与思考(1)---软件测试基础