Is java.util.Scanner that slow?
        Posted  
        
            by Cristian Vrabie
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Cristian Vrabie
        
        
        
        Published on 2010-03-15T11:47:38Z
        Indexed on 
            2010/03/15
            11:49 UTC
        
        
        Read the original article
        Hit count: 339
        
Hi guys, 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:
Scanner in = new Scanner(new BufferedInputStream(getAssets().open("vertexes.off")));
final float[] vertexes = new float[nrVertexes];
for(int i=0;i<nrVertexFloats;i++){
    vertexes[i] = in.nextFloat();
}
It seems however that this is incredibly slow (it took 30 minutes to read 10,000 floats!) - as tested on the 2.1 emulator. What's going on? I don't remember Scanner to be that slow when I used it on the PC (truth be told I never read more than 100 values before). Or is it something else, like reading from an asset input stream?
Thanks for the help!
© Stack Overflow or respective owner