You need to better specify how the words will be written in your text and textview file. Whether they will all be on the same line or each separated by a line break.
Anyway, I've done a general implementation that works for both cases:
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); // saída do textview
BufferedReader entrada = new BufferedReader(new FileReader("bd.txt")); // arquivo txt
String line = "";
String coresTextView = "";
String coresArquivoTexto = "";
while((line = reader.readLine()) != null)
coresTextView = coresTextView + line + " ";
while((line = entrada.readLine()) != null)
coresArquivoTexto = coresArquivoTexto + line + " ";
String[] cores = coresTextView.split(" ");
for(int i = 0; i < cores.length; i++)
if(coresArquivoTexto.replaceFirst(cores[i], "").equals(coresArquivoTexto))
System.out.println("AVISO: " + cores[i] + " não está no arquivo texto!");
else
coresArquivoTexto = coresArquivoTexto.replaceFirst(cores[i], "");
reader.close();
entrada.close();
To solve this problem you need to think of two lists: one with the colors of the textview and another with the colors of your text file.
You'll get the textview colors one by one and compare them to the entire list of colors in your text file. If you find the color of your textview list in the color list of the text file, you can remove the color from the list of the text file so you will not run the risk of finding it again if you have the same color twice in the colorview list of the textview .
In my implementation, I used Strings as the "color lists" that I quoted in the explanation above. The String ColorsTextView takes the lines of the textview and makes a separate join by spaces. Then, it separates all the words of the String by space and plays in the vector of Strings cores . With this, I have each color of the textview in a position of my vector Strings .
The String ColorsText is a String that joins all the colors found in the text file, separating them by space.
Next comes the loop to go through all the colors found in the textview. Within the loop has the condition that makes the comparison to see if the color is present in the text file:
if(coresArquivoTexto.replaceFirst(cores[i], "").equals(coresArquivoTexto))
Here is a simple manipulation of String. If the textview's color String vector is not present in the text string's Text String, then the .replaceFirst function will return the String TextText without any changes. With this, we know that the color is not present in the text file.
Now, if the color of the textview's Text Strings vector is present in the text file, we'll update the String ColorsTextbook by removing the color we just checked. We do this by associating the variable with the .replaceFirst function that should return the String without the color passed as a parameter.
coresArquivoTexto = coresArquivoTexto.replaceFirst(cores[i], "");
And this does the job you want!
I do not know how many colors and sizes of text files you want to work with, it may be that the String variable used does not support as many words as the text or textview file you are using. In that case, you might want to change the type to lists, for example, or even associate color names with numbers 1-9, and you can have a String with thousands of code characters that indicate colors.
Note: In this implementation be careful with spaces in your text and textview files, remember that the .split ("") function will split the String exactly into a space, if you have more than one space between the colors of your files, this can cause problems in running the program