0

I want to write a JAVA program that can convert any file into binary form and store it into a text file.

And when another JAVA program that takes the above generated text file to regenerate the original file.

Here binary form refers to the the format of ones and zeros in which the data is stored in permanent memory like HDDs.

NOTE : I don't want a binary file that is not readable, I just want to see those 1 and 0 written in a text file.

Example :

I have a video like "hello.mkv" --> I give this file's path to program 1 --> It generates a file "output.txt" consisting of ones and zeros ---> I give this file's path to program 2 --> It gives back me the original file "hello.mkv".

I know it's weired and I am not sure whether it is possible or not.

1
  • All files are stored in binary form; what you want is convert such bits to a human 0 and 1 string representation ( what will result in a increase of the file by eight; 8 bits of the 0 or 1 ASCII char for each represented bit of the source file ). You can start with stackoverflow.com/questions/12310017/… and stackoverflow.com/questions/11528898/… Pay careful attention to the comments about Java use 8-bit signed integers. Also, it seems that Java 8 have new binary functions not present there Commented May 6, 2021 at 19:31

1 Answer 1

0
f = open('file1.mp3', 'rb')

file_content = f.read()

f.close()

This is how a file can be opened in binary mode in python, where b mentioned in the file open function specifies the files to be opened in binary mode. The above code is an example.

Sign up to request clarification or add additional context in comments.

1 Comment

OP wants a Java solution, not a Python one

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.