Android use File.listFiles OOM

21 views Asked by At

Fatal Exception: java.lang.OutOfMemoryError: Failed to allocate a 222 byte allocation with 2097152 free bytes and 9MB until OOM; failed due to fragmentation (required continguous free 16384 bytes for a new buffer where largest contiguous free 12288 bytes)

      at java.lang.StringFactory.newStringFromChars(StringFactory.java)
       at java.lang.AbstractStringBuilder.toString(AbstractStringBuilder.java:629)
       at java.lang.StringBuilder.toString(StringBuilder.java:663)
       at java.io.File.join(File.java:213)
       at java.io.File.<init>(File.java:153)
       at java.io.File.<init>(File.java:118)
       at java.io.File.filenamesToFiles(File.java:843)
       at java.io.File.listFiles(File.java:782)

Android calculate File size. File.listFiles will cause OOM in android 5,6,7

I try to use Files.walkFileTree but it must be used above android 8, is there solution used in android 5,6,7???

0

There are 0 answers