Blackberry: Read a text file packaged in the project (faster)

戏子无情 提交于 2020-01-14 15:59:09

问题


I've tried this approach:

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800620/How_To_-_Add_plain_text_or_binary_files_to_an_application.html?nodeid=800687&vernum=0

But it's REALLY slow for slightly large text files. Does anyone know of a better way of reading a plain text file that is included in the project? Is there a way to use FileConnection?


回答1:


Figured it out using a combination of information:

IOUtilities.streamToBytes(is);

Directly on the input stream. So a more complete example would be as follows:

Class classs = Class.forName("com.packagename.stuff.FileDemo");

InputStream is = classs.getResourceAsStream("/test");

byte[] data = IOUtilities.streamToBytes(is);

String result = new String(data);

Deal? Deal.



来源:https://stackoverflow.com/questions/3267881/blackberry-read-a-text-file-packaged-in-the-project-faster

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!