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 5963715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:18:10+00:00 2026-05-22T19:18:10+00:00

What I am trying to do is read from a text file where each

  • 0

What I am trying to do is read from a text file where each line has the path to a file and then space for a separator and a hash that accompanies it. So I call checkVersion() and loadStrings(File f_) returns a String[], one place for each line. When I try to check the hashes however I end up with something that isn’t even hex and is twice as long as it should be, it’s probably something obvious that my eyes are just overlooking. The idea behind this is an auto-update for my game to save bandwidth, thanks for your time.

The code is fixed, here is the final version if anyone else has this issue, thanks a lot everyone.

void checkVersion() {
  String[] v = loadStrings("version.txt");
  for(int i=0; i<v.length; i++) {
    String[] piece = split(v[i], " ");  //BREAKS INTO FILENAME, HASH
    println("Checking "+piece[0]+"..."+piece[1]);

    if(checkHash(piece[0], piece[1])) {
      println("ok!");
    } else {
      println("NOT OKAY!");
      //CONTINUE TO DOWNLOAD FILE AND THEN CALL CHECKVERSION AGAIN
    }
  }
}

boolean checkHash(String path_, String hash_) {
  return createHash(path_).equals(hash_);
}

byte[] messageDigest(String message, String algorithm) {
  try {
  java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm);
  md.update(message.getBytes());
  return md.digest();
  } catch(java.security.NoSuchAlgorithmException e) {
    println(e.getMessage());
    return null;
  }
} 

String createHash(String path_) {
  byte[] md5hash = messageDigest(new String(loadBytes(path_)),"MD5");
  BigInteger bigInt = new BigInteger(1, md5hash);
  return bigInt.toString(16);
}
  • 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-22T19:18:11+00:00Added an answer on May 22, 2026 at 7:18 pm

    The String.getBytes() method returns the bytes that represent the character encodings for the string. It doesn’t parse it into bytes that represent a number in some arbitrary radix. For example "AA".getBytes() would yield you 0x41 0x41 on windows, not 10101010b, which is what it appears you were expecting? To get that you could, for example Byte.parseByte("AA", 16)

    The library you’re using to create hashes probably has a method for taking back in its own string representation. How to convert back depends on the representation, which you didn’t give us.

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

Sidebar

Related Questions

I'm trying to read commands from a text file and execute each line from
I'm trying to read a line of text from a text file and put
We are trying to read each word from a text file and replace it
I am trying to read values from a text file using the Qt code
I am trying to read some info from a text file by using windows
I'm trying to read a list of items from a text file and format
I'm trying to create a list of tasks that I've read from some text
I am trying to read in a file that has HTML list items with
Part 1 I'm trying to read a text file and then copy into another
I'm trying to read specific values from the text file (below): Current Online Users:

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.