Android的 - strings.xml中对文本文件。这是更快? [英] Android - Strings.xml versus text files. Which is faster?

查看:136
本文介绍了Android的 - strings.xml中对文本文件。这是更快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含共99833字,但每个字母分开的字典数据库。
我测试dictionaryA.txt其中包含3922字。

I have a dictionary database which contains a total of 99,833 words but separated per letter. I am testing dictionaryA.txt which contains 3922 words.

案例1:

当我输入一个字,我想查查,可以说算盘
使用缓冲的读者,我的应用程序说论文没有响应等待 - 退出。如果我选择等待,它会返回字算盘及其定义。

When I enter a word I wanna look up, lets say "abacus", Using a buffered reader, My app says "Thesis is not responding. Wait - Quit". If I choose wait, it will return the word abacus and its definition.

code:

InputStream inputStream = getResources().openRawResource(R.raw.definitiona); 
                    try {
                        BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
                        String s = in.readLine();
                        String delimiter = " - ";
                        String del[];
                        while(s != null)
                        {
                            s = in.readLine().replaceAll("\\s+", " ");
                            del = s.split(delimiter);
                            if (enhancedStem.equals(del[0]))
                            {
                                in.close();
                                databaseOutput.setText(s);
                                break;
                            }                        
                        }
                        in.close();
                        }
                    catch (FileNotFoundException e) {
                        databaseOutput.setText("" + e);
                    }
                    catch (IOException e1) {
                        databaseOutput.setText("" + e1);
                    }

案例2:

当我输入一个字,我想查查,可以说算盘
使用的strings.xml(我在传递一个字符串数组整个3922字),它说的一样。我有它响应之前点击等待。

When I enter a word I wanna look up, lets say "abacus", using the strings.xml (i transferred the whole 3922 words in a string-array), it says the same. I have to click wait before it responds.

code:

String[] wordA = getResources().getStringArray(R.array.DictionaryA);
                String delimiter = " - ";
                String[] del;
                for (int wordActr = 0; wordActr <= wordA.length - 1; wordActr++)
                {
                    String wordString = wordA[wordActr].toString();
                    del = wordString.split(delimiter);

                    if (enhancedStem.equals(del[0]))
                    {
                        databaseOutput.setText(wordA[wordActr]);
                        break;
                    }
                    else
                        databaseOutput.setText("Word not found!");

                }

你能告诉我,哪个更好?我是否应该继续使用我的文本文件?或将其转移到strings.xml中,因为他们都慢慢地回应呢?和你有什么想法,我怎么能消除没有响应的问题?
在此先感谢!

Can you tell me which is better? Should I keep using my textfile? Or transfer them to the strings.xml since they both respond slowly anyway? And do you have any idea how I can eliminate the "Not responding" problem? Thanks in advance!

推荐答案

使用XML在一个文本文件的主要优点是

The main advantages of using an Xml over a text file are


  1. 如果有一个明确的结构,所以解析它是一个容易的任务。

  2. 您还可以定义架构的XML和有被你可以通过XML pretty容易穿过它变得类型安全的。

  3. 更好的性能。

  4. 更可靠。

所以它能够更好地使用XML ...

so its better to use xml ...

这篇关于Android的 - strings.xml中对文本文件。这是更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆