@Test public void whenReadFileThenResultLinesFromFile() { Cache cache = new Cache("c:/temp"); String result = cache.readFile("names.txt"); assertThat(result, is(String.format("Ivan%sVictor%sPetr%s", sep, sep, sep))); }
public String readFile(String file) { String pathFile = String.format("%s/%s", path, file); StringBuilder lines = new StringBuilder(); try (Scanner sc = new Scanner(new File(pathFile))) { while (sc.hasNextLine()) { lines.append(sc.nextLine()); lines.append(System.getProperty("line.separator")); } } catch (FileNotFoundException e) { e.printStackTrace(); } return lines.toString(); }
Cache { public String readFile(String file) { String pathFile = String.format("%s/%s", path, file); StringBuilder lines = new StringBuilder(); try (Scanner sc = new Scanner(new File(pathFile))) { while (sc.hasNextLine()) { lines.append(sc.nextLine()); lines.append(System.getProperty("line.separator")); } } catch (FileNotFoundException e) { e.printStackTrace(); } return lines.toString(); } }
Cache { public String readFile(String file) { String pathFile = String.format("%s/%s", path, file); StringBuilder lines = new StringBuilder(); try (Scanner sc = new Scanner(new File(pathFile))) { while (sc.hasNextLine()) { lines.append(sc.nextLine()); lines.append(System.getProperty("line.separator")); } } catch (FileNotFoundException e) { e.printStackTrace(); } return lines.toString(); } Cache(String path); }
Cache { public String readFile(String file) { String pathFile = String.format("%s/%s", path, file); StringBuilder lines = new StringBuilder(); try (Scanner sc = new Scanner(new File(pathFile))) { while (sc.hasNextLine()) { lines.append(sc.nextLine()); lines.append(System.getProperty("line.separator")); } } catch (FileNotFoundException e) { e.printStackTrace(); } return lines.toString(); } Cache(String path); String select(String fileName); String readFile(String file); }
Cache { public String readFile(String file) { String pathFile = String.format("%s/%s", path, file); StringBuilder lines = new StringBuilder(); try (Scanner sc = new Scanner(new File(pathFile))) { while (sc.hasNextLine()) { lines.append(sc.nextLine()); lines.append(System.getProperty("line.separator")); } } catch (FileNotFoundException e) { e.printStackTrace(); } return lines.toString(); } Cache(String path); String select(String fileName); String readFile(String file);  }