好友
阅读权限10
听众
最后登录1970-1-1
|
//练习需求是将学生信息写入到文本
1.放在for循环里输出正常
for (Student student : students) {
StringBuilder sb = new StringBuilder();
sb.append(student.getName()+",").append(student.getChinese()+",").append(student.getMath()+",").append(student.getEnglish()+",").append(student.getSum());
bwriter.write(sb.toString());
bwriter.newLine();
bwriter.flush();
}
输出到文本:b,44,55,66,165
a,11,22,33,66
2.不放在循环里输出异常
StringBuilder sb = new StringBuilder();
for (Student student : students) {
sb.append(student.getName()+",").append(student.getChinese()+",").append(student.getMath()+",").append(student.getEnglish()+",").append(student.getSum());
bwriter.write(sb.toString());
bwriter.newLine();
bwriter.flush();
}
输出到文本:a,11,22,33,
a,11,22,33,66b,44,55,66,165
为什么要加进循坏里面?还有为什么添加那么多的apprend方法?
|
|
发帖前要善用【论坛搜索】功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。 |
|
|
|
|