Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
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 Oct 13, 2019 in Java by Ritik (3.5k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...