It is necessary to read from the file character-by-character into the array and further so that it is possible to process the elements of the array (search for Tacogo_to_Itelem and its removal from the array, but this is not the main thing)

    2 answers 2

    Like that:

    BufferedReader bufferedReader = new BufferedReader(new FileReader(".//src//file//file.txt")); int symbol = bufferedReader.read(); while (symbol != -1) { // Когда дойдём до конца файла, получим '-1' // Что-то делаем с прочитанным символом // Преобразовать в char: // char c = (char) symbol; symbol = bufferedReader.read(); // Читаем символ } 

      A character reading from a text file in an ArrayList (convenient if you don’t know the number of characters; you can replace it with LinkedList, depending on what operations you will need later)

       import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class Main { private static List<Character> chars = new ArrayList<>(); public static void main(String[] args) { BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(new File("myfile.txt"))); int c; while ((c = reader.read()) != -1) { chars.add((char) c); } reader.close(); } catch (IOException e) { e.printStackTrace(); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { e.printStackTrace(); } } } System.out.println(chars.toString()); } }