How to append text to an existing file in Java?
I am using the method mentioned in the solution and i am taking user input. But the text is appending with the last word. is there any way to add an new line there?
  Scanner sc= new Scanner(System.in); 
        System.out.print("Enter a string: ");  
        String str= sc.nextLine(); 
        try {
            Files.write(Paths.get("C:\\Users\\souravpal\\Documents\\Bandicam\\buddy.txt"), str.getBytes(), StandardOpenOption.APPEND);
        }catch (IOException e) {
            //exception handling left as an exercise for the reader
        }
 
     
    