Read Binary File

Read bytes from a binary file and print their length.

PythonBeginner
Python
# Program to read a binary file

filename = input("Enter binary filename: ")

try:
    with open(filename, "rb") as f:
        data = f.read()
        print("Read", len(data), "bytes")
except FileNotFoundError:
    print("Binary file not found.")

Output

Enter binary filename: image.png
Read 10240 bytes

Opening in "rb" mode reads raw bytes rather than decoding text.