Reputation: 31
i will like some advice on webservice that im writing, basically was trying to implement a method with code......
public static void writeToCustomerFile(Vector<Customer> customer) throws IOException
{
String strFilePath = "./src/customer.txt";
BufferedWriter writer = new BufferedWriter(new FileWriter(strFilePath));
for (int i = 0; i < customer.size(); i++) {
writer.write("id," + customer.get(i).getName() + "," + customer.get(i).getSurname()+","+customer.get(i).getAccount()+","+customer.get(i).getBalance()+"\n");
}
writer.close();
}
but it keeps on giving the error message: illegal start of type.
im trying to write this to a file on the serverside using a vector
Bless frederick carter
Upvotes: 0
Views: 200
Reputation: 206856
Did you import class Vector
?
import java.util.Vector;
By the way, Vector
is an old legacy collection class. You should use List
and ArrayList
in new code - only use Vector
when you are dealing with old legacy code which you can't change.
import java.util.List;
public static void writeToCustomerFile(List<Customer> customers) throws IOException
{
// ... code here ...
}
To iterate over a list, use a "foreach"-style loop instead of explicitly looking up elements by index:
for (Customer cust : customers) {
writer.write("id," + cust.getName() + "," + cust.getSurname() + "," +
cust.getAccount() + "," + cust.getBalance() + "\n");
}
Upvotes: 1