当前位置:网站首页>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());
}
}
}
边栏推荐
- SAP ABAP 中 OpenSQL和Native SQL-05 本教程的目的不是教您 SQL 或数据库概念
- Unity game optimization (version 2) learning record 8
- DDD understanding of Domain Driven Design
- C language learning -17- function is passed in as a parameter
- [Shanda conference] private chat channel webrtc tools
- 数睿数据荣获第二届ISIG中国产业智能大会两项年度大奖
- C language learning -18-makefile file writing examples and how to generate and call dynamic libraries
- Program substitution function
- 【山大会议】项目初始化
- Mysql触发器
猜你喜欢

ArcGIS JS之 4.23之IIS本地部署与问题解决

Bridging the gap between open source databases and database services

SAP ABAP 对话框编程教程:中的模块池-09

Uni develops wechat applet to customize automatic camera detection (portrait + ID card)

Focus on creating a net red product. The xinjietu x70s is newly launched, starting from 87900

Alibaba cloud middleware's open source past

SAP ABAP 内部表:创建、读取、填充、复制和删除-06

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

10款超牛Vim插件,爱不释手了

数字人民币可以买理财产品了!建行APP在试点地区上线服务专区,实测体验如何?
随机推荐
SAP ABAP 表控制与示例-07
【山大会议】软件性能优化及bug修复
SAP ABAP 中 OpenSQL和Native SQL-05 本教程的目的不是教您 SQL 或数据库概念
SAP ABAP 子屏幕教程:在 SAP 中调用子屏幕-010
跨界融合创意创新,助力提高文旅夜游影响力
默认函数控制 =default 与 =delete
odoo本地文档功能开发记录
Simulation of vector
How to embody the value of knowledge management in business
C language learning -18-makefile file writing examples and how to generate and call dynamic libraries
数睿数据受邀参与南通企业数字化转型研讨会
The difference between nvarchar and varchar
Simulation Implementation of string
Deploy odoo to the server and configure it as a service
Dear students, don't read the textbooks any more. Just read this one for the complexity of time
CMake教程系列-00-简介
Research on ICT: domestic databases focus on the ICT market, and Huawei Gauss is expected to become the strongest
Gbase "library" special training of innovation and application Committee of Beijing fintech Industry Alliance
实现一个Container全局组件步骤(给还不会使用组件的新手一个思路,大佬绕道)
期货怎么开户?网上期货开户安全吗?