Questions tagged [eof]

End of file (commonly abbreviated EOF) is a condition in a computer operating system where no more data can be read from a data source.

From Wikipedia:

End of file (commonly abbreviated EOF) is a condition in a computer operating system where no more data can be read from a data source. The data source is usually called a file or stream.

EOF is also a macro defined in the <stdio.h> header of the C standard library. This macro:

expands to an integer constant expression, with type int and a negative value, that is returned by several functions to indicate end-of-file, that is, no more input from a stream;

For more information:

1831 questions
12
votes
1 answer

Why does an fread loop require an extra Ctrl+D to signal EOF with glibc?

Normally, to indicate EOF to a program attached to standard input on a Linux terminal, I need to press Ctrl+D once if I just pressed Enter, or twice otherwise. I noticed that the patch command is different, though. With it, I need to press Ctrl+D…
12
votes
1 answer

Java heap dump error with jmap command : Premature EOF

I have encountered below exception during execution of below command jmap -dump:format=b,file=heap_dump.bin output: Dumping heap to Exception in thread "main" java.io.IOException: Premature EOF at…
Ravindra babu
  • 37,698
  • 11
  • 250
  • 211
12
votes
4 answers

How to detect EOF in Java?

I've tried some ways to detect EOF in my code, but it still not working. I've tried using BufferedReader, Scanner, and using char u001a to flag the EOF, but still not make any sense to my code. Here is my last code : Scanner n=new…
Bertha Alan
  • 131
  • 1
  • 1
  • 6
12
votes
9 answers

(Exercise 1.6 K&R) How to verfiy that getchar() != EOF IS 0 OR 1?

I have just started to learn programming (C) as a hobby, by myself. I'm using K&R. main() { int c; while ((c = getchar()) != EOF) putchar(c); } Verify that getchar() != EOF IS 0 OR 1 I think I understand what is happening: c is assigned the…
BBedit
  • 7,037
  • 7
  • 37
  • 50
12
votes
2 answers

Reaching EOF with fgets

I'm writing a function that perform some authentications actions. I have a file with all the user_id:password:flag couples structured like this: Users.txt user_123:a1b2:0 user_124:a2b1:1 user_125:a2b2:2 This is the code: int main(){ /*...*/ …
Fabio Carello
  • 1,062
  • 3
  • 12
  • 30
12
votes
2 answers

std::getline throwing when it hits eof

std::getline throws exception when it gets an eof. this is how I am doing. std::ifstream stream; stream.exceptions(std::ifstream::failbit|std::ifstream::badbit); try{ stream.open(_file.c_str(), std::ios_base::in); }catch(std::ifstream::failure…
Dipro Sen
  • 4,350
  • 13
  • 37
  • 50
11
votes
4 answers

bash EOF in if statement

I am trying to do an action in a IF ELSE statement in Bash, but receive an error like this one: Syntax error: end of file unexpected (expecting "fi") Now I am quite new to this, so probably the solution to my problem should not be that difficult…
Arthur
  • 921
  • 3
  • 13
  • 25
11
votes
5 answers

How to read user input until EOF in python?

I came across this problem in UVa OJ. 272-Text Quotes Well, the problem is quite trivial. But the thing is I am not able to read the input. The input is provided in the form of text lines and end of input is indicated by EOF. In C/C++ this can be…
rohan
  • 113
  • 1
  • 1
  • 6
11
votes
5 answers

Reading a web page in Java IOException Premature EOF

I am frequently getting a 'Premature EOF' Exception when reading a web page. The following is the StackTrace java.io.IOException: Premature EOF at sun.net.www.http.ChunkedInputStream.readAheadBlocking(ChunkedInputStream.java:556) at…
Ranjith
  • 1,623
  • 3
  • 21
  • 34
11
votes
3 answers

How to prevent InputStream.readObject() from throwing EOFException?

I serialize an object and save it as a file on my HDD. When I'm reading it, in only some occasions it throws EOFException. After couple of hours debugging I am not able to find a problem. Here is my code: public void serialize(MyClass…
Jama A.
  • 15,680
  • 10
  • 55
  • 88
10
votes
2 answers

What is the meaning of EOF exceptions in hadoop namenode connections from hbase/filesystem?

This is both a general question about java EOF exceptions, as well as Hadoop's EOF exception which is related to jar interoperability. Comments and answers on either topic are acceptable. Background I'm noting some threads which discuss a cryptic…
jayunit100
  • 17,388
  • 22
  • 92
  • 167
10
votes
1 answer

How can I clear EOF on stdin ($*IN) after gettig it with get / prompt in Raku?

In my program, I'd like to read a line from $*IN in a loop, and for this I can use either get or prompt; however, I noticed that if I end my input immediately with EOF (e.g., with Ctrl-D in Linux / MacOS) then any subsequent uses of get or prompt…
cowbaymoo
  • 1,202
  • 5
  • 14
10
votes
2 answers

Python EOF for multi byte requests of file.read()

The Python docs on file.read() state that An empty string is returned when EOF is encountered immediately. The documentation further states: Note that this method may call the underlying C function fread() more than once in an effort to acquire…
dawg
  • 98,345
  • 23
  • 131
  • 206
10
votes
1 answer

Bash: append text to last line of file

How can I add a percentage symbol % to the end of the last line in a text file? I do not want the % to be on a new line, it must be at the end of the last line. Thanks!
Rich
  • 682
  • 1
  • 6
  • 14
10
votes
6 answers

Can read(2) return zero when not at EOF?

According to the man page for read(2), it only returns zero when EOF is reached. However, It appears this is incorrect and that it may sometimes return zero, perhaps because the file is not ready to be read yet? Should I call select() to see if it…
WilliamKF
  • 41,123
  • 68
  • 193
  • 295