I want to write a code that would work with a large bd database. I set myself a task to write a simple code that would read the database in chunks (my computer is not very strong and I cannot open it) and pull out some data (for example, email addresses) . I used the org.apache.commons:commons-csv:1.2 library org.apache.commons:commons-csv:1.2 . The database provides large blocks with data (for example, letters in which there are addresses). I got something like this:
public class MainClass { static public final Pattern PATTERN_MAIL = Pattern.compile("([a-z0-9_-]+\\.)*[a-z0-9_-]+@[a-z0-9_-]+(\\.[a-z0-9_-]+)*\\.[az]{2,6}"); public static void main(String[] args) throws Exception { Matcher getMail; String path = "cpath"; Reader in = new FileReader(path); File file = new File("data.text"); FileWriter fileWriter = new FileWriter(file.getAbsoluteFile()); BufferedWriter bufWriter = new BufferedWriter(fileWriter); int k=1; Iterable<CSVRecord> records = CSVFormat.EXCEL.parse(in); List<CSVRecord> tableStr = new ArrayList<>(); for (CSVRecord record : records) { tableStr.add(record); if (tableStr.size() == 5) { System.out.println("list"+k); for (int i=0; i<tableStr.size(); i++) { getMail=PATTERN_MAIL.matcher(tableStr.get(i).toString()); while(getMail.find()) { bufWriter.write(tableStr.get(i).toString().substring(getMail.start(), getMail.end()) +"\n"); } } tableStr.clear(); System.out.println("tableStr deleted"); k++; } } bufWriter.close(); System.out.println("buf was closed"); The code works, according to the regular expression, from the information can get addresses. But the problem is that when a large text block is processed with information, it takes a long time. Experienced programmers, please tell me how you can increase the speed of this code? I agree that the code is clumsy, but I'm new to it, I'm learning. Your advice will not be superfluous.