We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d4f28d7 commit 936b820Copy full SHA for 936b820
1 file changed
src/main/java/org/apache/commons/io/FileUtils.java
@@ -1849,7 +1849,9 @@ public static String readFileToString(final File file) throws IOException {
1849
*/
1850
public static byte[] readFileToByteArray(final File file) throws IOException {
1851
try (InputStream in = openInputStream(file)) {
1852
- return IOUtils.toByteArray(in); // Do NOT use file.length() - see IO-453
+ long fileLength = file.length();
1853
+ // file.length() may return 0 for system-dependent entities, treat 0 as unknown length - see IO-453
1854
+ return fileLength > 0 ? IOUtils.toByteArray(in, fileLength) : IOUtils.toByteArray(in);
1855
}
1856
1857
0 commit comments