我怎样才能读取文件中的每一个字母?

How can I read every letter from the file?

我有这部分代码。我可以从代码中读取所有行。但我想分别读取(读取)每个字母并将其放入数组中。我该怎么做? 例如:文件中有数字 00010,我想将它放入这样的数组中:array[0,0,0,1,0]

public void readTest()
    {
            try
            {
                    InputStream is = getResources().getAssets().open("test.txt");
                    BufferedReader br = new BufferedReader(new InputStreamReader(is));
                    String st = "";
                    StringBuilder sb = new StringBuilder();

                    while ((st=br.readLine())!=null)
                    {
                            sb.append(st);
                    }

                    br.close();

            }catch (IOException e)
            {
                    Log.d(TAG, "Error: " + e);
            }
    }

使用br.read()。它将returns字符作为整数

ArrayList<char> charArray = new ArrayList<>();
int i;
while ((i = br.read()) != -1) {
    char c = (char) i;
    charArray.add(c);
}

直接来自 JavaDoc:

public int read() throws IOException - Reads a single character.

您应该添加读取每个字符串并通过遍历将其字母添加到数组中,如下所示:

 while ((st=br.readLine())!=null) {
            sb.append(st);


            for (int i = 0; i < st.length(); i++) {
                char c = st.charAt(i);        
                yourArray.add(c);
            }
 }