0 votes
1 view
in Java by (920 points)

How do I convert a java.io.File to a byte[]?

1 Answer

0 votes
by (13.2k points)

To convert a java.io.File to byte[], see the function below

public static byte[] toByteArray(InputStream input, int size)

If the size is not known you can skip mentioning that parameter.This method will return the required byte array.

This method throws an I0Exception if the InputStream mentioned doesn’t match the size given or illegalArgumentException   if size is less than zero.

Related questions

0 votes
1 answer
asked Jul 9, 2019 in Java by prachi95 (1.1k points)
0 votes
1 answer
asked Jul 9, 2019 in Java by Aditya98 (1.3k points)
0 votes
1 answer
asked Oct 13, 2019 in Java by Ritik (3.5k points)
0 votes
1 answer
asked Sep 29, 2019 in Java by Shubham (3.9k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...