exampleJson/src/mmk/JsonConn.java

25 lines
541 B
Java
Raw Normal View History

2026-05-25 01:02:36 +03:00
package mmk;
import java.io.IOException;
import java.net.URL;
import java.util.Scanner;
public class JsonConn {
public static void main(String[] args) throws IOException {
URL url = new URL("https://random-word-api.herokuapp.com/word?number=10");
String inline = "";
Scanner scanner = new Scanner(url.openStream());
//Write all the JSON data into a string using a scanner
while (scanner.hasNext()) {
inline += scanner.nextLine();
}
scanner.close();
System.out.println(inline);
}
}