As we all know, both the code will lead to the same result
public class MainApp { public static void main(String[] args) throws IOException { URL google = new URL("http://www.google.com"); google.openConnection(); BufferedReader reader = new BufferedReader(new InputStreamReader(google.openStream())); reader.lines().forEach(System.out::println); } }
and
public class MainApp { public static void main(String[] args) throws IOException { URL google = new URL("http://www.google.com"); BufferedReader reader = new BufferedReader(new InputStreamReader(google.openStream())); reader.lines().forEach(System.out::println); } } (google.openStream ())); public class MainApp { public static void main(String[] args) throws IOException { URL google = new URL("http://www.google.com"); BufferedReader reader = new BufferedReader(new InputStreamReader(google.openStream())); reader.lines().forEach(System.out::println); } } ).; public class MainApp { public static void main(String[] args) throws IOException { URL google = new URL("http://www.google.com"); BufferedReader reader = new BufferedReader(new InputStreamReader(google.openStream())); reader.lines().forEach(System.out::println); } }
So what's the point when you use google.openConnection()?
user6538026
source share