Printing every line from a file?
Heyya! I have this class: The append-method works wonderfully. However, when I try to print each line, things get really buggy. Say I appended some sentences in the test.txt: SentenceA SentenceB SentenceC How will I have to change the getting()-method so it is going to print each line? import java.util.*; import java.io.*; import java.lang.*; public class Test { private Formatter form; private Scanner sc; public void append(String text) { try(FileWriter file = new FileWriter("test.txt", true); BufferedWriter bw = new BufferedWriter(file); PrintWriter out = new PrintWriter(bw)) { out.println(text); } catch (IOException e) { e.printStackTrace(); } } public void getting() { try { File f = new File("test.txt"); FileReader fr = new FileReader(f); BufferedReader br = new BufferedReader(fr); while ((br.readLine())!=null) { System.out.println(br.readLine()); } br.close(); } catch(Exception e) { e.printStackTrace(); } } }