Android file copy

后端 未结 2 662
再見小時候
再見小時候 2020-12-20 01:41

I am finding that reading one line at a time from a text file on the SD card is rather slow. I imagine that it might be quicker if the file is in internal memory, so I want

2条回答
  •  南笙
    南笙 (楼主)
    2020-12-20 02:25

    One of the truisims of CS that only becomes more true with time as CPUs get faster is: I/O is slow.

    If you want speed, generally your best bet is to do as few I/O's as possible. Ideally, find out how big that file is, allocate that much memory, and then read the entire thing in one big I/O. Then you can just access the data from program memory. If you might not have enough RAM for every concievable file size then you might have to do a bit more work, but this is what you should strive for.

提交回复
热议问题