When I am writing text in this txt file, there either is no space between the new string and the old existing string, or there is extra lines, which messes up my other algorithms.
public String writeStudent(String file, String name)
{
String txt = "";
//set through put method
try(FileWriter fw = new FileWriter(file + ".txt", true);
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter out = new PrintWriter(bw))
{
out.println(name + "\r\n");
//save userinput into class1.txt
txt ="added: " + name;
}
catch(IOException e)
{
System.out.println("error");
e.printStackTrace();
// detact error
}
return txt;
}
This is the code I am using to writing in txt, using (name + "\r\n") gives me extra empty lines.