G
G
GennadyPHP2018-08-14 19:07:11
Java
GennadyPHP, 2018-08-14 19:07:11

How to rewrite c# code to java?

Hello, how can I rewrite c# code in java. It is necessary that the Android application receive the content of the URL

WebClient wc = new WebClient();
string response = wc.downloadString("example.com/api");

Thanks

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikita Egorov, 2018-08-14
@GennadyPHP

Of. documentation
Will output 100 json objects.

import java.net.*;
import java.io.*;

public class URLReader {
    public static void main(String[] args) throws Exception {

        URL oracle = new URL("http://jsonplaceholder.typicode.com/posts");
        BufferedReader in = new BufferedReader(
        new InputStreamReader(oracle.openStream()));

        String inputLine;
        while ((inputLine = in.readLine()) != null)
            System.out.println(inputLine);
        in.close();
    }
}

G
Gennady Knyazkin, 2018-08-15
@GennadyX

Use retrofit2 to work with api

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question