In fact, I have a method that reads words from a file and writes it into an array. Sample text file:
www mail login password
www1 mail1 login1 password1
but I want to understand which words on the new line and which not, tell me how to do it, now my code looks like this.
BufferedReader fileReader; String buf[] = new String[0]; { try { String str = null; fileReader = new BufferedReader(new FileReader("C:\\...\\src\\model\\file.txt")); while ((str = fileReader.readLine()) != null) { //ΠΏΠΎΠ»ΡΡΠ°Π΅ΠΌ Π½ΠΎΠ²ΡΠ΅ ΡΠ»ΠΎΠ²Π° String[] newWords = str.split(" "); //ΡΠΎΠ·Π΄Π°Π΅ΠΌ ΡΠ°ΡΡΠΈΡΠ΅Π½Π½ΡΠΉ ΠΌΠ°ΡΡΠΈΠ² String[] result = new String[buf.length + newWords.length]; //ΠΊΠΎΠΏΠΈΡΡΠ΅ΠΌ ΡΠ»Π΅ΠΌΠ΅Π½ΡΡ Π² ΠΌΠ°ΡΡΠΈΠ² System.arraycopy(buf, 0, result, 0, buf.length); System.arraycopy(newWords, 0, result, buf.length, newWords.length); //ΠΏΡΠΈΡΠ²Π°ΠΈΠ²Π°Π΅ΠΌ ΡΠ΅Π·ΡΠ»ΡΡΠΈΡΡΡΡΠΈΠΉ ΠΌΠ°ΡΡΠΈΠ² ΡΠ΅ΠΊΡΡΠ΅ΠΌΡ buf = result; } fileReader.close(); } catch (IOException e) { e.printStackTrace(); } }