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.

Tushar
  • 167
  • 7
  • 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 https://stackoverflow.com/questions/12310017/how-to-convert-a-byte-to-its-binary-string-representation and https://stackoverflow.com/questions/11528898/convert-byte-to-binary-in-java 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 – ClassicOcean May 06 '21 at 19:31

1 Answers1

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.

Korashen
  • 2,144
  • 2
  • 18
  • 28
Vikhyat
  • 136
  • 3