uj5u.com熱心網友回復:
兄弟,你這問的啥問題啊,圖都沒截全uj5u.com熱心網友回復:
老鐵到檔案中就結束了。后面的不用管
uj5u.com熱心網友回復:
class Student{public String name;
public String sex;
public String jiguan;
public Student(String name,String sex,String jiguan){
this.name=name;
this.sex=sex;
this.jiguan=jiguan;
}
public String getString(){
return name+","+sex+","+jiguan;
}
}
class Test{
public static void main(String[] args){
ArrayList<Student> list = new ArrayList<Student>();
Student st1= new Student("姓名1","男","籍貫1");
Student st2= new Student("姓名2","男","籍貫2");
Student st3= new Student("姓名3","男","籍貫3");
Student st4= new Student("姓名4","男","籍貫4");
Student st5= new Student("姓名5","男","籍貫5");
list.add(st1);
list.add(st2);
list.add(st3);
list.add(st4);
list.add(st5);
String str="";
for(Student stu : list){
str+=stu.getString()+"\n\r";
}
writeToFile("你的姓名.txt",str);
}
public static void writeToFile(String f,String content){
File file = new File(f);
FileOutputStream outputStream;
try {
outputStream = new FileOutputStream(f);
outputStream.write(content.getBytes());
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/100499.html
標籤:Java SE
上一篇:java注釋問題
