How to read large files (a single continuous string) in Java?
问题 I am trying to read a very large file (~2GB). Content is a continuous string with sentences (I would like to split them based on a '.'). No matter how I try, I end up with an Outofmemoryerror. BufferedReader in = new BufferedReader(new FileReader("a.txt")); String read = null; int i = 0; while((read = in.readLine())!=null) { String[] splitted = read.split("\\."); for (String part: splitted) { i+=1; users.add(new User(i,part)); repository.saveAll(users); } } also, inputStream = new