fist issue
This commit is contained in:
parent
29b807fa85
commit
fe943f43fa
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
|
@ -1,16 +1,11 @@
|
|||
# ---> Java
|
||||
# Compiled class file
|
||||
# Java
|
||||
target/
|
||||
bin/
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
|
|
@ -20,7 +15,5 @@
|
|||
*.tar.gz
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
replay_pid*
|
||||
|
||||
# do NOT ignores
|
||||
!lib/*
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>exampleJson</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.release=enabled
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
package mmk;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
public class JsonConn2 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
HttpURLConnection conn = null;
|
||||
BufferedReader reader;
|
||||
String line;
|
||||
StringBuffer responceContent = new StringBuffer();
|
||||
|
||||
try {
|
||||
URL url = new URL("https://random-word-api.herokuapp.com/word?number=10");
|
||||
|
||||
conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setConnectTimeout(5000);
|
||||
conn.setReadTimeout(5000);
|
||||
|
||||
int status = conn.getResponseCode();
|
||||
|
||||
if(status > 299) {
|
||||
reader = new BufferedReader(new InputStreamReader(conn.getErrorStream()));
|
||||
while((line = reader.readLine()) != null) {
|
||||
responceContent.append(line);
|
||||
}
|
||||
reader.close();
|
||||
}
|
||||
else {
|
||||
reader = new BufferedReader(new InputStreamReader(conn.getErrorStream()));
|
||||
while((line = reader.readLine()) != null) {
|
||||
responceContent.append(line);
|
||||
}
|
||||
reader.close();
|
||||
}
|
||||
|
||||
System.out.println(responceContent.toString());
|
||||
|
||||
} catch (MalformedURLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally {
|
||||
conn.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
package mmk;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
public class JsonConn3 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
HttpURLConnection conn = null;
|
||||
BufferedReader reader;
|
||||
String line;
|
||||
StringBuffer responceContent = new StringBuffer();
|
||||
|
||||
try {
|
||||
//URL url = new URL("https://random-word-api.herokuapp.com/word?number=10");
|
||||
URL url = new URL("http://10.234.226.19:5000/ml/2500/400/11000/4/50/1.5/18.5/6.0/1/0/1");
|
||||
|
||||
conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setConnectTimeout(5000);
|
||||
conn.setReadTimeout(5000);
|
||||
|
||||
int status = conn.getResponseCode();
|
||||
|
||||
if(status > 299) {
|
||||
reader = new BufferedReader(new InputStreamReader(conn.getErrorStream()));
|
||||
while((line = reader.readLine()) != null) {
|
||||
responceContent.append(line);
|
||||
}
|
||||
reader.close();
|
||||
}
|
||||
else {
|
||||
reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
while((line = reader.readLine()) != null) {
|
||||
responceContent.append(line);
|
||||
}
|
||||
reader.close();
|
||||
}
|
||||
|
||||
System.out.println(responceContent.toString());
|
||||
|
||||
} catch (MalformedURLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally {
|
||||
conn.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue