Skip to content
Permalink
Browse files
Java Networking Code
Sample Code in java Networking
  • Loading branch information
sareenv committed Feb 8, 2019
0 parents commit 90d1b13bb3529e2a6f5bb5f20ca450f3675a87d3
Showing 1 changed file with 45 additions and 0 deletions.
@@ -0,0 +1,45 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

/**
*
* @author Data
*/
public class JavaApplication3 {

/**
* @param url
* @throws java.io.IOException
*/

// This allows to integrate teh api in Java... !
// Looks good.
public void networking(String url) throws IOException{
URL urls;
urls = new URL("http://api.openweathermap.org/data/2.5/weather?APPID=d98cf0f33972375849da99fef900c4f8&units=metric&q=london");
HttpURLConnection con = (HttpURLConnection) urls.openConnection();
con.setRequestMethod(" HttpURLConnection con = (HttpURLConnection) urls.openConnection();GET");
BufferedReader sampleBufferReader;
sampleBufferReader = new BufferedReader(new InputStreamReader(con.getInputStream()));
// String buffer - need to study about what string buffer is ?

String inputLine;
StringBuilder content = new StringBuilder();

while((inputLine = sampleBufferReader.readLine()) != null){
content.append(inputLine);
}
sampleBufferReader.close();
System.out.println(content);
}

public static void main(String[] args) throws IOException {
// TODO code application logic here
JavaApplication3 javaT = new JavaApplication3();
javaT.networking("");
}

}

0 comments on commit 90d1b13

Please sign in to comment.