Home > Back-end >  Java mentally, iron friends to give directions.
Java mentally, iron friends to give directions.

Time:10-01

CodePudding user response:

Brother, you this ask what question ah, haven't cut the whole figure

CodePudding user response:

reference 1/f, Aaron Xiao response:
brother, you this ask what problem, figure didn't cut all

Brother to a file is over, no need to worry about at the back of the

CodePudding user response:

The 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;
Enclosing jiguan=jiguan;
}
Public String get String () {
Return the name + + + ", "sex", "+ jiguan;
}
}
The class Test {
Public static void main (String [] args) {
ArrayList List=new ArrayList (a);
1 Student st1=new Student (" name ", "male" and "the native place 1");
2 Student st2=new Student (" name ", "male", "native 2");
Student st3=new Student (" name 3 ", "male", "native 3");
Student st4=new Student (name of "4", "male", "native place 4");
Student st5=new Student (name of "5", "male" and "native place 5");
List. The add (st1);
List. The add (st2);
List. The add (st3);
List. The add (st4);
List. The add (st5);
String STR="";
For (Student stu: list) {
STR +=stu. Get string () + "\ n \ r";
}
WriteToFile (" your name. TXT ", STR);
}
Public static void writeToFile (String, the String content) {
The File File=new File (f);
FileOutputStream outputStream.
Try {
OutputStream=new FileOutputStream (f);
OutputStream. Write (content. getBytes ());
OutputStream. Close ();

} the catch (Exception e) {
e.printStackTrace();

}
}
}
  • Related