DigestOutputStream.toString() method in Java with Examples
The toString() method of java.security.DigestOutputStream class used to provide the object of DigestOutputStream in string format.
Syntax:
public String toString()
Return Value: This method returns the object of DigestOutputStream in string format.
Note: All the programs in this article won’t run on online IDE as no ‘name’ file exists. You can check this code on Java compiler on your system. To check this code, create a file ‘name’ on your system.
Below are the examples to illustrate the toString() method:
Example 1:
// Java program to demonstrate // toString() method import java.security.*; import java.util.*; import java.io.*; public class GFG { public static void main(String[] argv) { try { // creating the object of MessageDigest // and getting instance // By usng getInstance() method MessageDigest sr = MessageDigest.getInstance("MD5"); // creating and intializing // object of OutputStream OutputStream is = new FileOutputStream( "f:/java/name.txt"); // creating and intializing // object of DigestOutputStream DigestOutputStream di = new DigestOutputStream(is, sr); // getting the string // representation of DigestOutputStream // using toString() method String str = di.toString(); // display the result System.out.println("Status : " + str); } catch (NoSuchAlgorithmException e) { System.out.println("Exception thrown : " + e); } catch (NullPointerException e) { System.out.println("Exception thrown : " + e); } catch (FileNotFoundException e) { System.out.println("Exception thrown : " + e); } } } |
Status : [Digest Output Stream] MD5 Message Digest from SUN,
Example 2:
// Java program to demonstrate // toString() method import java.security.*; import java.util.*; import java.io.*; public class GFG { public static void main(String[] argv) { try { // creating the object of MessageDigest // and getting instance // By usng getInstance() method MessageDigest sr = MessageDigest.getInstance("SHA-1"); // creating and intializing // object of OutputStream OutputStream is = new FileOutputStream( "f:/java/name.txt"); // creating and intializing // object of DigestOutputStream DigestOutputStream di = new DigestOutputStream(is, sr); // getting the string representation // of DigestOutputStream // using toString() method String str = di.toString(); // display the result System.out.println("Status : " + str); } catch (NoSuchAlgorithmException e) { System.out.println("Exception thrown : " + e); } catch (NullPointerException e) { System.out.println("Exception thrown : " + e); } catch (FileNotFoundException e) { System.out.println("Exception thrown : " + e); } } } |
Status : [Digest Output Stream] SHA-1 Message Digest from SUN,
Recommended Posts:
- Java lang.Long.numberOfTrailingZeros() method in Java with Examples
- Java.util.Collections.rotate() Method in Java with Examples
- Java lang.Long.builtcount() method in Java with Examples
- Java lang.Long.lowestOneBit() method in Java with Examples
- Java lang.Long.numberOfLeadingZeros() method in Java with Examples
- Java lang.Long.highestOneBit() method in Java with Examples
- Java lang.Long.reverse() method in Java with Examples
- Java.util.Collections.disjoint() Method in java with Examples
- Java lang.Long.byteValue() method in Java with Examples
- Java.lang.Short toString() method in Java with Examples
- Java 8 | ArrayDeque removeIf() method in Java with Examples
- Java Clock tickMinutes() method in Java with Examples
- Java Clock withZone() method in Java with Examples
- Set add() method in Java with Examples
- Set contains() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


