static void fileWriter(Request request) throws IOException { try(FileWriter writer = new FileWriter("information.txt")) { writer.write(request.toString()); //Need a new line in the file each time the method is called! } 
  • When outputting, I get everything in one line, how to switch to a new line during output to a file?

  • The output contains data about ip, host, port, I will be glad to any help!

    2 answers 2

    Alternatively, you can get all the parameters of the request and form Parameter-Value strings.

     Enumeration params = request.getParameterNames(); while(params.hasMoreElements()) { String param = (String) params.nextElement(); writer.write(param + ": " + request.getParameter(param) + ";" + System.getProperty("line.separator")); } 
       try(Writer writer = new FileWriter("information.txt",true)){ writer.write(request.toString()); writer.write(System.getProperty("line.separator")); writer.close(); 

      - Another option!