This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Pass arguments via system properties | |
// Usage: jshell -v -R-Dfile=test.txt system-props.jsh | |
String fileName = System.getProperty("file") | |
System.out.println("Input file name is: " + fileName) | |
/exit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create and delete directories | |
// Usage: jshell --class-path ../libs/commons-io.jar work-with-directories.jsh | |
import org.apache.commons.io.FileUtils | |
String content = "JShell Scripting" | |
File file = new File("test.txt") | |
// Create text file | |
FileUtils.writeStringToFile(file, content) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// HTTP Client GET | |
// Usage: jshell --add-modules jdk.incubator.httpclient http-get.jsh | |
import jdk.incubator.http.* | |
var client = HttpClient.newHttpClient() | |
var request = HttpRequest.newBuilder().uri(new URI("https://medium.com/adambgoode")).build() | |
var response = client.send(request, HttpResponse.BodyHandler.asString()) | |
System.out.println(response.body()) | |
/exit |