Skip to content

Commit 4e0dc95

Browse files
committed
✨ Add Files
1 parent 576a279 commit 4e0dc95

4 files changed

Lines changed: 31 additions & 2 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ dependency-reduced-pom.xml
1010
buildNumber.properties
1111
.mvn/timing.properties
1212

13-
# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)
13+
# Avoid ignoring Maven wrapper jar files (.jar files are usually ignored)
1414
!/.mvn/wrapper/maven-wrapper.jar
1515
### JetBrains template
1616
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This repository contains some new feature code after Java8, which runs on top of
99
- [http](src/main/java/io/github/biezhi/java11/http)
1010
- [processor](src/main/java/io/github/biezhi/java11/processor)
1111
- [try with resources](src/main/java/io/github/biezhi/java11/trywithresources)
12+
- [files](src/main/java/io/github/biezhi/java11/files)
1213

1314
# License
1415

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package io.github.biezhi.java11.files;
2+
3+
import java.nio.file.Files;
4+
import java.nio.file.Paths;
5+
6+
/**
7+
* Files 读写文本文件
8+
*
9+
* @author biezhi
10+
* @date 2018/7/31
11+
*/
12+
public class Example {
13+
14+
public static void main(String[] args) throws Exception {
15+
String text = "Hello biezhi.";
16+
17+
// 写入文本
18+
Files.writeString(Paths.get("hello.txt"), text);
19+
20+
// 读取文本
21+
String readText = Files.readString(Paths.get("hello.txt"));
22+
System.out.println(text.equals(readText));
23+
24+
// 删除文本
25+
Files.delete(Paths.get("hello.txt"));
26+
}
27+
28+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public static void uploadFile() throws Exception {
106106

107107
HttpRequest request = HttpRequest.newBuilder()
108108
.uri(new URI("http://localhost:8080/upload/"))
109-
.POST(HttpRequest.BodyPublishers.ofFile(Paths.get("/tmp/file-to-upload.txt")))
109+
.POST(HttpRequest.BodyPublishers.ofFile(Paths.get("/tmp/files-to-upload.txt")))
110110
.build();
111111

112112
HttpResponse<Void> response = client.send(request, HttpResponse.BodyHandlers.discarding());

0 commit comments

Comments
 (0)