Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3219840
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:41:33+00:00 2026-05-17T15:41:33+00:00

Alright, so I’m writing a hex editor in Java and when I load in

  • 0

Alright, so I’m writing a hex editor in Java and when I load in a file around 2MB or bigger it just freezes. No errors show up though, so I’m not sure whats going on. Can anyone help me? This is the code:

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;
import java.util.Vector;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

public class HexEditor extends JFrame{
 JScrollPane hexScroll;
 JScrollPane byteScroll;
 JPanel panel;
 JTextArea hexArea;
 JTextArea byteArea;
 JFileChooser chooser;// = new JFileChooser();
 FileInputStream fin;
 JMenuBar menuBar;
 JMenu file;
  JMenuItem load;

 public HexEditor(){
  super("Cypri's java hex editor");
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  chooser = new JFileChooser();

  load = new JMenuItem("Load");
   load.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent event) {

     try{

      openFile();
      fin = new FileInputStream(chooser.getSelectedFile());

      int ch;
      StringBuffer strContent = new StringBuffer("");

      for(int i = 0; (ch = fin.read()) != -1; i++){
       String s = Integer.toHexString(ch);

       if(s.length() < 2)
        s = "0" + Integer.toHexString(ch);

       if(i < 10)
        strContent.append(" " + s.toUpperCase());

       else{
        strContent.append(" " + s.toUpperCase() + "\n");
        i = 0;
       }
      }

      hexArea.setText(strContent.toString());

      byte[] b = hexStringToByteArray(strContent.toString().trim());
      char[] chars = new char[b.length];
      String byteText = "";
      int newLine = 0;
      for(int i = 0; i < b.length; i++){
       chars[i] = (char) b[i];
       byteText += chars[i];

       newLine++;
       if(newLine > 10){
        byteText += "\n";
        newLine = 0;
       }
      }

      hexArea.setText(strContent.toString());
      byteArea.setText(byteText);
      packMe();
     }

     catch(Exception e){
      e.printStackTrace();
     }
    }
   });

  file = new JMenu("File");
  file.add(load);

  menuBar = new JMenuBar();

  menuBar.add(file);

  hexArea = new JTextArea();
  byteArea = new JTextArea();

  hexScroll = new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
  byteScroll = new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);

  panel = new JPanel();

  panel.add(hexScroll);
  panel.add(byteScroll);
  hexScroll.setViewportView(hexArea);
  byteScroll.setViewportView(byteArea);

  hexArea.setPreferredSize(new Dimension(200,200));
  byteArea.setPreferredSize(new Dimension(200,200));

  hexScroll.setPreferredSize(new Dimension(200,200));
  byteScroll.setPreferredSize(new Dimension(200,200));

  getContentPane().setLayout(new BorderLayout());
  getContentPane().add(BorderLayout.NORTH, menuBar);
  getContentPane().add(BorderLayout.CENTER, panel);
  pack();
  setVisible(true);
 }

 public static byte[] hexStringToByteArray(String s) {
     int len = s.length() -1;
     byte[] data = new byte[(len / 2) + 1];
     for (int i = 0; i < len; i += 2) {
         data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i+1), 16));
     }
     return data;
 }


 public void openFile(){
  chooser.showOpenDialog(null);
 }

 public void packMe(){
  pack();
 }

 public static void main(String[] args){
     HexEditor app = new HexEditor();
 }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:41:34+00:00Added an answer on May 17, 2026 at 3:41 pm

    2MB would already result in a big String. You need to break the file into pages for display, and only convert a buffer of a few KB at once.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, currently I have my SWF hitting a php file that will go and
Alright, I'm trying to read a comma delimited file and then put that into
Alright. So I figure it's about time I get into unit testing, since everyone's
Alright, I have been doing the following (variable names have been changed): FileInputStream fis
Alright. So I have a very large amount of binary data (let's say, 10GB)
Alright, after doing a ton of research and trying almost every managed CPP Redist
Alright, I know how the fieldset / legend works out in HTML. Say you
Alright, quick question. A server is running in Eastern Time. PHP program needs to
Alright. I have a query that looks like this: SELECT SUM(`order_items`.`quantity`) as `count`, `menu_items`.`name`
Alright, so I have a query that looks like this: SELECT `orders`.*, GROUP_CONCAT( CONCAT(

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.