Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I would guess that you need to set the checksum to the md5 hash of the file's <em><strong>contents</strong></em>, not the hash of the <em>path-name</em>. </p> <p>Why would they (google) care about the path? It makes no sense at all. Forgive me if I misinterpreted your code, but I think you have misconceived the concept of file checksums. </p> <p>Anyway, what you need to do is eat (digest) the file and not the path:</p> <pre><code> import java.security.*; import java.util.*; import java.math.*; import java.io.*; public class MD5 { private MessageDigest mDigest; private File openFile; private FileInputStream ofis; private int fSize; private byte[] fBytes; public MD5(String filePath) { try { mDigest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { System.exit(1); } openFile = new File(filePath); } public String toString() { try { ofis = new FileInputStream(openFile); fSize = ofis.available(); fBytes = new byte[fSize]; ofis.read(fBytes); } catch (Throwable t) { return "Can't read file or something"; } mDigest.update(fBytes); return new BigInteger(1, mDigest.digest()).toString(16); } public static void main(String[] argv){ MD5 md5 = new MD5("someFile.ext"); System.out.println(md5); } } </code></pre> <p>So the error in your snippet above is here: </p> <pre><code> messageDigest.update(String.valueOf(file.hashCode()).getBytes()); </code></pre> <p>Now, I can show that my class gives the correct md5sum of the <em>file</em> which is most likely what you need. Just read the javadoc of the method if you don't trust me: <a href="http://gdata-java-client.googlecode.com/svn/trunk/java/src/com/google/gdata/data/docs/DocumentListEntry.java" rel="nofollow">http://gdata-java-client.googlecode.com/svn/trunk/java/src/com/google/gdata/data/docs/DocumentListEntry.java</a> What it says is: * Set the MD5 checksum calculated for the document. ... nothing about the path's checksum :) </p> <p>here: </p> <pre><code>$ echo "Two dogs are sleeping on my couch" &gt; someFile.ext $ echo "Two dogs are sleeping on my couch" |md5sum 1d81559b611e0079bf6c16a2c09bd994 - $ md5sum someFile.ext 1d81559b611e0079bf6c16a2c09bd994 someFile.ext $ javac MD5.java &amp;&amp; java MD5 1d81559b611e0079bf6c16a2c09bd994 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload