Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
java-training
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lihui.wang
java-training
Commits
e2e6fe62
Commit
e2e6fe62
authored
Nov 01, 2018
by
lihui.wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
io
parent
1ca1cc83
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
0 deletions
+40
-0
demo1/src/test/java/cn/freemud/demo/HomeworkTests.java
+40
-0
No files found.
demo1/src/test/java/cn/freemud/demo/HomeworkTests.java
View file @
e2e6fe62
...
...
@@ -2,6 +2,7 @@ package cn.freemud.demo;
import
org.junit.Test
;
import
java.io.*
;
import
java.util.*
;
public
class
HomeworkTests
{
...
...
@@ -63,4 +64,43 @@ public class HomeworkTests {
System
.
out
.
print
(
a
+
" "
);
}
/**
* io 字节流
*/
@Test
public
void
ioDemo
(){
File
file
=
new
File
(
"D:\\a.text"
);
try
{
OutputStream
os
=
new
FileOutputStream
(
file
);
String
ts
=
"hello world!"
;
byte
[]
data
=
ts
.
getBytes
();
os
.
write
(
data
);
}
catch
(
FileNotFoundException
e
)
{
System
.
out
.
println
(
"找不到文件"
);
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
"字节流输入文件错误"
);
e
.
printStackTrace
();
}
}
/**
* 字符流
*/
@Test
public
void
ioDemo1
(){
File
file
=
new
File
(
"D:\\b.text"
);
try
{
FileWriter
fs
=
new
FileWriter
(
file
);
String
ts
=
"hello world,b.text!"
;
fs
.
write
(
ts
);
/**
* 字符流的文件会存入到缓冲池里,要随用随关闭
*/
fs
.
close
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
"字符流输入文件错误"
);
e
.
printStackTrace
();
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment