0

My program should get a path for a text file as input. The text is just 1's and 0's and the program needs to read it as bytes. This is what I got so far, it's working but I know there's a better way

public void transform(String input_File)
{
    File file = new File(input_file);

    BufferedReader br = null;
    try {
        br = new BufferedReader(new FileReader(file));
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    String org_text = null;
    String byte_val;
    try {
        while ((org_text = br.readLine()) != null)
        {
            for (int i = 0; i < org_text.length();i += 8)
            {
                byte_val = org_text.substring(i, i+8);
                int ch = Integer.parseInt(byte_val, 2);
                //some more lines here, but it dosn't matter

            }

        }
    } catch (IOException e)
    {
        e.printStackTrace();
    }
Sirp
  • 1

0 Answers0