Skip to content

Instantly share code, notes, and snippets.

@adambgoode
adambgoode / system-props.java
Created April 17, 2018 18:04
JShell sample: passing arguments via system properties
// 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
@adambgoode
adambgoode / work-with-directories.java
Created April 17, 2018 18:02
JShell sample: work with directories and files
// 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)
// 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