I have tried a lot with many ways to write a program that : write a one byte value in a file as it is.. for example write 01010101 in a file.. then i want to read the file and print what i wrote.So it should display 01010101. None of my codes worked so. Any help? Because i am writing a compression program it essential to be 1 byte and not 8
import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.FileInputStream;
import java.io.File;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main2 {
public static void main(String[] args) throws Exception {
DataOutputStream dos = new DataOutputStream(new FileOutputStream("Text.t"));
dos.writeBytes(String.valueOf(01010101));
File file = new File("Text.t");
BufferedReader br = new BufferedReader(
new InputStreamReader(
new FileInputStream(file)));
System.out.println(br.readLine());
dos.close();
br.close();
}
}
It works well with binary code that starst with 1 but with 0 not.. for example for 01010101 it shows 266305