Sujet : [JAVA] HttpURLConnection |
darklord22 |
J'ai eu le même problème que toi en son temps. Une solution très bourine mais qui fonctionne c'est de faire un truc du genre:
Code :
- /**
- * Checks wheter this file exists or not
- * This should avoid requests on a 404
- * Warning this method can decrease the performance
- * 0,1 sec per file with good network performance
- * @ param f
- * The file to check
- * @return true if the file exists
- */
- private boolean validFile(WebFile f) {
- long start = new Date().getTime();
- try {
- URL u = new URL(f.getURL());
- HttpConnectionTools t = new HttpConnectionTools(u);
- if (t.isOK())
- return true;
- else
- return false;
- }
- catch (IOException e) {
- Logger.debug(
- this,
- "Verifying "
- + f.getURL()
- + " failed ! done in "
- + (new Date().getTime() - start)
- + " msec" );
- return false;
- }
- }
|
A+ |