I want to verify a downloaded file, I have found some method to do so, such as, compare the file name after download in the download folder. However, I want to have further checking to ensure the downloaded is no different with the original one. How can I do? or It is possible to do that?
Hello,
File myFile = new File("C:\\test\\test.txt")println myFile.length()
returns a size of the file in **bytes. **
1 Like
for better check of content of file, you can use checksum functions like MD5:
@Keyword def generateMD5(final File file) { MessageDigest digest = MessageDigest.getInstance("MD5") file.withInputStream(){is-> byte[] buffer = new byte[8192] int read = 0 while( (read = is.read(buffer)) > 0) { digest.update(buffer, 0, read); } } byte[] md5sum = digest.digest() BigInteger bigInt = new BigInteger(1, md5sum) return (bigInt.toString(16).padLeft(32, '0')) }
usage:
println CustomKeywords.'com.swre.tools.generateMD5'(new File('pathToFile.anything'))
1 Like
Thank Marek Melocik
Hello,
File myFile = new File("C:\\test\\test.txt")println myFile.length()
returns a size of the file in **bytes. **
That’s work for me!