Is java.util.Scanner that slow?

后端 未结 7 1674
悲&欢浪女
悲&欢浪女 2021-02-07 08:17

In a Android application I want to use Scanner class to read a list of floats from a text file (it\'s a list of vertex coordinates for OpenGL). Exact code is:

Sc         


        
7条回答
  •  野的像风
    2021-02-07 09:04

    I got the exactly same problem. It took 10 minutes to read my 18 KB file. In the end I wrote a desktop application that converts those human readable numbers into machine-readable format, using DataOutputStream.

    The result was astonishing.

    Btw, when I traced it, most of the Scanner method calls involves regular expressions, whose implementation is provided by com.ibm.icu.** packages (IBM ICU project). It's really overkill.

    The same goes for String.format. Avoid it in Android!

提交回复
热议问题