Write to a csv file with JSP without overwriting what you already have

Asked

Viewed 44 times

0

I have this code below to record information in the csv file, but whenever I record something, what I have already written is lost. How do I get him to add a line with the new information keeping what he already has?

String fName = "cadastros.csv";
FileOutputStream fos = new FileOutputStream(fName);
PrintWriter pw = new PrintWriter(fos);
pw.println(request.getParameter("nome") + ";" + request.getParameter("email"));
pw.close();
fos.close();

1 answer

0

Read the file in a string, add the new content in that string and then save the string with the old and new content.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.