First of all, hello! I am new here, and I come with a very newbish question. For some reason, this decided not to work, and I spent a couple of hours trying to realize why, and I just can't manage to.
Here is the code:
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; public class Learn { public static void readFile(String file) { String[] arr; BufferedReader br = null; ArrayList<String> str = new ArrayList<String>(); try { String currentLine; br = new BufferedReader (new FileReader(file)); while((currentLine = br.readLine()) != null) { if(currentLine.contains(".")) { arr = currentLine.split("."); System.out.println(arr.length); for(int i = 0; i < arr.length; i++) { System.out.println(arr[i]); if(!(arr[i].equals(""))) str.add(arr[i]); } } for(String st : str) { System.out.println(st); } } } catch(IOException e) { e.printStackTrace(); } finally { try { if( br != null ) br.close(); } catch(IOException e) { e.printStackTrace(); } } } }
and the file it is reading is
The curentLine.contains(".") expression evaluates to true, but the code stops there (I mean, just skips the rest). I added that println there, and the output is 0; so basically, something goes wrong in the split().This is a test for sentences. This sentence is one. This is another
Any help is greatly appreciated!
Thank you for your time!
Best regards,
BrreaKer