Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Events
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
JavaDevelopRep
Java
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
Java
/
day20
/
day20总结.txt
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
85 lines (73 loc) · 1.77 KB
master
Breadcrumbs
Java
/
day20
/
day20总结.txt
Copy path
Top
File metadata and controls
Code
Blame
85 lines (73 loc) · 1.77 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
1:递归(理解)
(1)方法定义中调用方法本身的现象。
(2)注意事项:
A:一定要有出口,否则就是死递归
B:不要次数过多,否则内存溢出
C:构造方法不能递归使用
(3)举例:
A:老和尚给小和尚讲故事
B:学Java
(4)案例:(A,B必须掌握,C,D要看懂)
A:递归求阶乘
B:递归解决兔子问题
C:递归输出指定目录下指定后缀名的文件的绝对路径
D:递归删除带内容的目录
2:IO流(掌握)
(1)IO流:
A:用于实现设备间的数据传输问题
上传文件,下载文件
B:java中数据以IO流的形式传输
C:针对流操作的对象都在io包中
(2)IO流的分类
A:流向
输入流
输出流
B:数据类型
字节流
字符流
a:如果没有明确指定,默认按照数据类型分。
b:通过windows记事本打开并能够读懂的文件,就用字符流。
否则,用字节流。
如果你不知道,建议永远使用字节流。
(3)FileOutputStream写数据
步骤:
A:创建字节输出流对象
B:调用写数据功能
C:释放资源
代码体现:
FileOutputStream fos = new FileOutputStream("fos.txt");
fos.write("helloworld".getBytes());
fos.close();
几个小问题:
A:创建字节输出流对象做了几件事情?
B:写完数据后,为什么要close()呢?
C:如何实现数据的换行呢?
D:如何实现数据的追加写入呢?
E:要求能够看懂加入异常处理后的IO代码
(4)FileInputStream读数据
步骤:
A:创建字节输入流对象
B:调用读数据功能
C:释放资源
代码体现:
FileInputStream fis = new FileInputStream("fis.txt");
//方式1:一次读取一个字节
int by = 0;
while((by=fis.read())!=-1) {
System.out.print((char)by);
}
//方法2:一次读取一个字节数组
byte[] bys = new byte[1024];
int len = 0;
while((len=fis.read(bys))!=-1) {
System.out.print(new String(bys,0,len));
}
fis.close();
(5)案例:
复制文件
数据源:读数据
目的地:写数据
A: 项目路径下的a.txt,到项目路径下的b.txt
B: c:\\a.txt到d:\\b.txt
C: e:\\林青霞.jpg到项目路径下的mn.jpg
D: e:\\哥有老婆.mp4到项目路径下的copy.mp4
You can’t perform that action at this time.