Problem with reading binary files i.e(exe)

Hello all, I’ve got problem with reading binary files(exe) (visual studio 2022).

I want to read file into TextEditor component. When I choose txt file, everything is fine, content is read , every char changed into decimal representation and put into editor. When I try to make, the same thing with exe file, application freezes :frowning:
I tried to create new_output_string with new operator, I tried to use char table with new, I tried to use fscanf() and getwc() and nothing. When I used Builder 6.0 before there was no problem.:frowning:

The code is:
in main class are

class MainComponent  : public juce::Component
  juce::TextButton open_button{"Open"};
  juce::TextEditor texteditor;

        setSize (700, 500);

open_button.onClick = [this](){

/*creating fileChooser component to select the file to be opened*/

fChooser = std::make_unique<juce::FileChooser>("Choose file", 
defaultDirectory, "*.*", true, false, this);

auto folderChooserFlags = juce::FileBrowserComponent::openMode 
| juce::FileBrowserComponent::canSelectDirectories | 

/*launching fileChooser*/

fChooser->launchAsync(folderChooserFlags, [this](const juce::FileChooser& chooser)
   juce::File chosenFile = chooser.getResult();
   juce::String tmp_path= chosenFile.getFullPathName();
   char file_path[555];
   // temporary int to store the value from file stream and file pointers
   int tmp_int;
   FILE *file_1,*file_2;

   juce::FileInputStream input_stream{chosenFile};
   juce::int64 size_of_file;
   juce::String new_tmp_string;
   juce::String new_output_string="";

   // getting size of the choosen file and changing it to string type
   juce::String str = juce::String(size_of_file);
   // creating log file to make sure the file path and size of the file are correct
   //reading binary content of the file , converting it into characters, spacing and 
   //creating brand new string that will be put into text editor 
            new_output_string+=" , ";}
    // setting content of text_editor component 
    // setting text of button to see if size is correct 
    //setting new path so at the next showing fileChooser it's path is the same        


It’s probably about the Juce TextEditor not being designed to handle huge amounts of text. There might be some algorithmic inefficiency in it that makes it take so much time to execute the setText method that it effectively looks like a freeze, but maybe if you waited for a really long time, it might finish in the end. What happens if you don’t, for testing purposes, call the setText method of the editor at all? Did you try a release build too?

I tried tu put max 2 MB source of exe file (it changed into numbers) but it’s still 2MB. In Paragon Partition Manager there were option to read whole disk partitions and WinHex also had such option. Yes, You’re right, I should check wheter it’s problem of TextEditor,but possible options are so many, I hoped for quick help. Anyway, I’ll try to check it.

Doing some tests here, looks like already doing the string seems to take an extremely long time, before even attempting to put the string into the TextEditor component. I also tried this before the while loop, but it didn’t help :


There might be some issue in juce::String already that makes it extremely slow for this use case.

Tryied to use VS2022 release option while compilng and after few minutes I pressed “Cancel” button.

Yeah, release build doesn’t seem to help the issue.

The following code works much faster and the application will actually start, but the text editor is going to work a bit slowly even in release builds :

    std::stringstream ss;
    while (!feof(file_2)) {
        auto tmp_int = fgetc(file_2);
        ss << tmp_int << " , ";
    juce::String new_output_string;
    new_output_string = ss.str();
    m_edit.setText(new_output_string, false);

Tested with a 2 megabyte binary file here.

Hm. Just opened 257 KB image file but it took a quiet long time. Now there is something we can work with. Thanks. If anyone has a better solution it would be nice.