Skip to content

Commit 30713dc

Browse files
committed
✨ Update Time And Single File
1 parent 4e0dc95 commit 30713dc

4 files changed

Lines changed: 59 additions & 1 deletion

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ This repository contains some new feature code after Java8, which runs on top of
1010
- [processor](src/main/java/io/github/biezhi/java11/processor)
1111
- [try with resources](src/main/java/io/github/biezhi/java11/trywithresources)
1212
- [files](src/main/java/io/github/biezhi/java11/files)
13+
- [time](src/main/java/io/github/biezhi/java11/time)
14+
- [single file](src/main/java/io/github/biezhi/java11/singlefile)
1315

1416
# License
1517

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package io.github.biezhi.java11.singlefile;
2+
3+
/**
4+
* 你可以在当前源码的目录下执行
5+
* <p>
6+
* java HelloWorld.java 运行这个文件的 main 方法
7+
*
8+
* 该命令相当于
9+
*
10+
* javac -d <memory> HelloWorld.java
11+
* java -cp <memory> HelloWorld
12+
*
13+
* 该特性来自 <a href="http://openjdk.java.net/jeps/330">JEP330</a>
14+
* @author biezhi
15+
* @date 2018/8/1
16+
*/
17+
public class HelloWorld {
18+
19+
public static void main(String[] args) {
20+
System.out.println("Hello Guys, this is Java 11.");
21+
}
22+
23+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package io.github.biezhi.java11.time;
2+
3+
import java.time.Duration;
4+
import java.util.concurrent.TimeUnit;
5+
6+
/**
7+
* Time convert
8+
*
9+
* @author biezhi
10+
* @date 2018/8/1
11+
*/
12+
public class Example {
13+
14+
public static void main(String[] args) {
15+
long day = TimeUnit.DAYS.convert(Duration.ofHours(24));
16+
System.out.println(day == 1);
17+
18+
// 1 天
19+
System.out.println(TimeUnit.DAYS.convert(Duration.ofHours(26)));
20+
21+
// 1 分钟
22+
System.out.println(TimeUnit.MINUTES.convert(Duration.ofSeconds(60)));
23+
}
24+
25+
}

src/main/java/io/github/biezhi/java11/var/Example.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.github.biezhi.java11.var;
22

3+
import java.io.File;
4+
import java.io.FileInputStream;
35
import java.nio.file.Files;
46
import java.nio.file.Paths;
57
import java.util.ArrayList;
@@ -27,9 +29,15 @@ public static void main(String[] args) throws Exception {
2729

2830
System.out.println("字节数组: " + bytes);
2931

30-
for (var b: bytes) {
32+
for (var b : bytes) {
3133
// TODO
3234
}
3335

36+
try (var foo = new FileInputStream(new File(""))) {
37+
System.out.println(foo);
38+
} catch (Exception e) {
39+
// ignore
40+
}
41+
3442
}
3543
}

0 commit comments

Comments
 (0)