Skip to content
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 }}
LiengChien
JavaSE6Tutorial
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
JavaSE6Tutorial
/
example
/
CH14
/
BufferedStreamDemo.java
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
45 lines (36 loc) · 1.35 KB
master
Breadcrumbs
JavaSE6Tutorial
/
example
/
CH14
/
BufferedStreamDemo.java
Copy path
Top
File metadata and controls
Code
Blame
45 lines (36 loc) · 1.35 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
package
onlyfun
.
caterpillar
;
import
java
.
io
.*;
public
class
BufferedStreamDemo
{
public
static
void
main
(
String
[]
args
) {
try
{
byte
[]
data
=
new
byte
[
1
];
File
srcFile
=
new
File
(
args
[
0
]);
File
desFile
=
new
File
(
args
[
1
]);
BufferedInputStream
bufferedInputStream
=
new
BufferedInputStream
(
new
FileInputStream
(
srcFile
));
BufferedOutputStream
bufferedOutputStream
=
new
BufferedOutputStream
(
new
FileOutputStream
(
desFile
));
System
.
out
.
println
(
"複製檔案:"
+
srcFile
.
length
() +
"位元組"
);
while
(
bufferedInputStream
.
read
(
data
) != -
1
) {
bufferedOutputStream
.
write
(
data
);
}
// 將緩衝區中的資料全部寫出
bufferedOutputStream
.
flush
();
// 關閉串流
bufferedInputStream
.
close
();
bufferedOutputStream
.
close
();
System
.
out
.
println
(
"複製完成"
);
}
catch
(
ArrayIndexOutOfBoundsException
e
) {
System
.
out
.
println
(
"using: java UseFileStream src des"
);
e
.
printStackTrace
();
}
catch
(
IOException
e
) {
e
.
printStackTrace
();
}
}
}
You can’t perform that action at this time.