怎么知道conection.connect()是否连接到url? [英] How do know conection.connect() is connect to url or not?
本文介绍了怎么知道conection.connect()是否连接到url?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建conn = jUrl.openConnection();
当我使用conn.connect()来识别url我不知道连接是不是?
但现在我想知道我是否连接到url?
我尝试过:
i use conn.getconnectLenght()
但是每个
i create a conn of conn = jUrl.openConnection();
when i use conn.connect() to conncet url i dont know connection is or not?
but now i want to know is i connect to url or not?
What I have tried:
i use conn.getconnectLenght()
but its value is same every where
推荐答案
的值都相同你可以捕获错误引发的异常,如连接到URL(Java™教程>自定义网络>使用URL) [ ^ ]。
请参阅使用函数的文档,了解可能引发的各种行为:
URL(Java Platform SE 7):openConnection() [< a href =https://docs.oracle.com/javase/7/docs/api/java/net/URL.html#openConnection()target =_ blanktitle =New Window> ^ ]
URLConnection(Java平台) SE 7):connect() [ ^ ]
You can catch the exceptions that are thrown upon errors as described at Connecting to a URL (The Java™ Tutorials > Custom Networking > Working with URLs)[^].
See the documentation for the used functions which kinds of execptions might be thrown:
URL (Java Platform SE 7 ): openConnection() [^]
URLConnection (Java Platform SE 7 ): connect()[^]
这篇关于怎么知道conection.connect()是否连接到url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文