当前位置:网站首页>5.文件的读写(学生类)
5.文件的读写(学生类)
2022-06-22 15:02:00 【小木荣】
5 文件读写
定义学生类数组,有N个人(N=5),包括姓名和语数外三名课的成绩,实现学生数组的文件读写。
import java.io.*;
import java.util.Scanner;
public class Student {
final static int N = 5;
private String name;
private int Chinese, English, math;
public Student(String name, int Chinese, int English, int math) {
this.name = name;
this.Chinese = Chinese;
this.math = math;
this.English = English;
}
public static void main(String[] args) {
Student[] stu = new Student[N];
int num = 0;
stu[0] = new Student("李1白", 99, 99, 99);
stu[1] = new Student("李2白", 89, 89, 90);
stu[2] = new Student("李3白", 120, 120, 60);
stu[3] = new Student("李4白", 120, 120, 60);
stu[4] = new Student("李5白", 120, 120, 60);
File fp = new File("student.txt");
try {
PrintWriter output = new PrintWriter(fp);
for (int i = 0; i<N; i++) {
output.print(stu[i].name + ' ');
output.print("语文:" + stu[i].Chinese);
output.print("数学:" + stu[i].English);
output.println("英文:" + stu[i].math);
num++;
}
output.close();
} catch (IOException e) {
System.out.println(e.toString());
}
try {
String stus = null;
Scanner input = new Scanner(fp);
for (int i = 0; i < num; i++) {
stus = input.nextLine();
System.out.println(stus);
}
input.close();
} catch (IOException e) {
System.out.println(e.toString());
}
}
}
边栏推荐
- 让pycharm项目里面的文本模板支持jinjia2语法
- Rosbag use command
- 中信建投证券是跟启牛学堂存在什么关系?开证券账户安全吗
- Promouvoir l'adaptation compatible et permettre le développement collaboratif du Service Express adaptatif gbase en mai
- 实现一个Container全局组件步骤(给还不会使用组件的新手一个思路,大佬绕道)
- String的模拟实现
- Make the text template in pycharm project support jinjia2 syntax
- Mr. Du built a domestic non garlic Statistics Platform
- SAP价值流程&帮助请求流程-011
- SAP ABAP BAPI-016
猜你喜欢

SAP ABAP BAPI-016
![[Newman] postman generates beautiful test reports](/img/5c/b95c1c475e69d69acad75215ea9565.png)
[Newman] postman generates beautiful test reports

实现一个Container全局组件步骤(给还不会使用组件的新手一个思路,大佬绕道)

Unity游戏优化(第2版)学习记录8

Navicat premium connecting to Oracle database (Graphic tutorial)

跨界融合创意创新,助力提高文旅夜游影响力

wallys/WiFi6 MiniPCIe Module 2T2R 2×2.4GHz 2x5GHz

【山大会议】应用设置模块

【LeetCode】9、回文数

C language learning -17- function is passed in as a parameter
随机推荐
mysql - sql执行过程
[Shanda conference] definitions of some basic tools
【山大会议】多人视频通话 WebRTC 工具类搭建
[Shanda conference] application setting module
【山大会议】项目引入 Redux
Binary search (integer binary)
SAP ABAP BAPI-016
[Shanda conference] private chat channel webrtc tools
Promoting compatibility and adaptation, enabling coordinated development of gbase may adaptation Express
Batch export excel zip using zipfile, openpyxl and flask
SAP ABAP 中的 Smart Forms-014
数睿数据受邀参与南通企业数字化转型研讨会
Program substitution function
Deploy odoo to the server and configure it as a service
[Shanda conference] project introduces Redux
Unity game optimization (version 2) learning record 8
【山大会议】WebRTC基础之对等体连接
Linux安装mysql
Gbase "library" special training of innovation and application Committee of Beijing fintech Industry Alliance
Dear students, don't read the textbooks any more. Just read this one for the complexity of time