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
bing.liu
java-training
Commits
6b06b603
Commit
6b06b603
authored
Nov 01, 2018
by
bing.liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
asdsa
parent
b16f7cb9
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
162 additions
and
0 deletions
+162
-0
demo1/src/test/java/cn/freemud/demo/Test.java
+162
-0
No files found.
demo1/src/test/java/cn/freemud/demo/Test.java
0 → 100644
View file @
6b06b603
/**
* Copyright (C), 2015-2018, 非码网络科技有限公司
* FileName: Test
* Author: bing.liu
* Date: 2018-11-01 17:59
* Description:
*/
package
cn
.
freemud
.
demo
;
import
java.io.*
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.LinkedList
;
/**
* @author bing.liu
* @create 2018-11-01
* @versions 1.0.0
*/
public
class
Test
{
private
static
int
len
=
5
;
private
static
String
IOtext1
=
"io content-one"
;
private
static
String
IOtext2
=
"io content-tow"
;
@org
.
junit
.
Test
public
void
test1
()
throws
IOException
,
InterruptedException
{
mainAction
();
}
public
static
void
mainAction
()
throws
IOException
,
InterruptedException
{
HashMapAction
();
ArrayListAction
();
LinkedListAction
();
IOAction
();
new
ThreadDemo
(
"Thread-one"
).
start
();
new
ThreadDemo
(
"Thread-two"
).
start
();
Thread
.
sleep
(
1000
);
new
RunnableDemo
(
"Runnable-one"
).
start
();
new
RunnableDemo
(
"Runnable-two"
).
start
();
}
public
static
void
HashMapAction
()
{
HashMap
<
Integer
,
String
>
hashMap
=
new
HashMap
();
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
hashMap
.
put
(
i
,
"hashMapValue"
.
concat
(
String
.
valueOf
(
i
)));
}
hashMap
.
forEach
((
k
,
v
)
->
System
.
out
.
println
(
"hashMap Key:"
.
concat
(
k
.
toString
()).
concat
(
",values:"
).
concat
(
v
)));
System
.
out
.
println
();
}
public
static
void
ArrayListAction
()
{
ArrayList
arrayList
=
new
ArrayList
();
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
arrayList
.
add
(
"arrayList"
.
concat
(
String
.
valueOf
(
i
)));
}
arrayList
.
forEach
((
k
)
->
System
.
out
.
println
(
"arrayList content:"
.
concat
(
k
.
toString
())));
System
.
out
.
println
();
}
public
static
void
LinkedListAction
()
{
LinkedList
linkedList
=
new
LinkedList
();
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
linkedList
.
add
(
"linkedList"
.
concat
(
String
.
valueOf
(
i
)));
}
linkedList
.
forEach
((
k
)
->
System
.
out
.
println
(
"linkedList content:"
.
concat
(
k
.
toString
())));
System
.
out
.
println
();
}
public
static
void
IOAction
()
throws
IOException
{
FileOutputStream
fos
=
new
FileOutputStream
(
"D:\\FileOutputStream.txt"
);
fos
.
write
(
IOtext1
.
getBytes
(
"UTF-8"
));
fos
.
close
();
FileInputStream
fr
=
new
FileInputStream
(
"D:\\FileOutputStream.txt"
);
byte
[]
buf
=
new
byte
[
1024
];
int
len
;
String
myStr
=
""
;
while
((
len
=
fr
.
read
(
buf
))
!=
-
1
)
{
myStr
+=
new
String
(
buf
,
0
,
len
,
"UTF-8"
);
}
System
.
out
.
println
(
myStr
);
FileWriter
fw
=
new
FileWriter
(
"D:\\FileWriter.txt"
);
fw
.
write
(
IOtext2
);
fw
.
close
();
FileReader
fr2
=
new
FileReader
(
"D:\\FileWriter.txt"
);
char
[]
buf2
=
new
char
[
1024
];
int
len2
=
fr2
.
read
(
buf2
);
String
myStr2
=
new
String
(
buf2
,
0
,
len2
);
System
.
out
.
println
(
myStr2
);
System
.
out
.
println
();
}
static
class
RunnableDemo
implements
Runnable
{
private
Thread
t
;
private
String
threadName
;
RunnableDemo
(
String
name
)
{
threadName
=
name
;
}
public
void
run
()
{
System
.
out
.
println
(
"Run "
+
threadName
);
try
{
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
System
.
out
.
println
(
"Thread: "
+
threadName
+
", "
+
i
);
Thread
.
sleep
(
50
);
}
}
catch
(
InterruptedException
e
)
{
System
.
out
.
println
(
"Thread "
+
threadName
+
" interrupted."
);
}
System
.
out
.
println
(
"Thread "
+
threadName
+
" esc."
);
System
.
out
.
println
();
}
public
void
start
()
{
System
.
out
.
println
(
"Star "
+
threadName
);
if
(
t
==
null
)
{
t
=
new
Thread
(
this
,
threadName
);
t
.
start
();
}
}
}
static
class
ThreadDemo
extends
Thread
{
private
Thread
t
;
private
String
threadName
;
ThreadDemo
(
String
name
)
{
threadName
=
name
;
}
public
void
run
()
{
System
.
out
.
println
(
"Run "
+
threadName
);
try
{
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
System
.
out
.
println
(
"Thread: "
+
threadName
+
", "
+
i
);
Thread
.
sleep
(
50
);
}
}
catch
(
InterruptedException
e
)
{
System
.
out
.
println
(
"Thread "
+
threadName
+
" interrupted."
);
}
System
.
out
.
println
(
"Thread "
+
threadName
+
" esc."
);
System
.
out
.
println
();
}
public
void
start
()
{
System
.
out
.
println
(
"Star "
+
threadName
);
if
(
t
==
null
)
{
t
=
new
Thread
(
this
,
threadName
);
t
.
start
();
}
}
}
}
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