Reputation: 1571
I'm trying to write multiple lines into a file but only one record of EmpID
, DeptID
and Salary
is getting stored. Below is the code snippet. How do I write multiple lines?
case 1:try
{
FileWriter fsalary_specific = new FileWriter(
new File("Salary_Specific.txt"));
DeptID = tokens[2];
String var_2 = tokens[3];
salary = Double.parseDouble(var_2);
fsalary_specific.write(EmpID+" "+DeptID+" "+salary+"\n");
fsalary_specific.close();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
Upvotes: 0
Views: 3213
Reputation: 5565
You need to open the file in "append" mode if you are re-opening it every time. Pass true
into the FileWriter
constructor like so:
FileWriter fsalary_specific = new FileWriter(new File("Salary_Specific.txt"), true);
Upvotes: 4
Reputation: 168845
See FileWriter(File,boolean)
. If that does not work for you, post an SSCCE.
Upvotes: 2