Where to put text files in directory in Android

前端 未结 2 1532
再見小時候
再見小時候 2020-12-14 01:00

I have a text file i want to include in my Android application, it is not a string file it is a standard text file. It contains data that defines the characteristics of a \"

相关标签:
2条回答
  • 2020-12-14 01:13

    You have to put your file in the assets folder as Waqas said.

    Now to access it you do it like that.

    I give you an example using BufferedReader

    BufferedReader reader = new BufferedReader(
                     new InputStreamReader(getAssets().open("YourTextFile.txt")));
    

    Be careful. In my case, I don't know why for now, I cannot read text files bigger than ~1MB and I had to split them in multiple small files. It seems other had the same problem of file size but I didn't find any information about that on Android developer site. If any one knows more about this ....

    FOLLOW UP

    My problem with the 1MB was due to a know bug/limitation of earlier versions of Android. Since using recent versions of Android, that problem is not present anymore.

    0 讨论(0)
  • 2020-12-14 01:22

    Use assets or raw folder in your android folders structure to keep that file. For more info read this

    0 讨论(0)
提交回复
热议问题