开发者

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

开发者 https://www.devze.com 2023-01-07 10:55 出处:网络
I\'ve tried this approach: http://www.blackberry.com/knowledgece开发者_StackOverflow中文版nterpublic/livelink.exe/fetch/2000/348583/800332/800620/How_To_-_Add_plain_text_or_binary_files_to_an_applic

I've tried this approach:

http://www.blackberry.com/knowledgece开发者_StackOverflow中文版nterpublic/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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消