J'ai un problème avec le téléchargement d'un fichier zip depuis une URL. Il fonctionne bien avec Firefox, mais avec mon application j'ai un 404.Java - Télécharger le fichier zip depuis l'url
Voici mon code
URL url = new URL(reportInfo.getURI().toString());
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
// Check for errors
int responseCode = con.getResponseCode();
InputStream inputStream;
if (responseCode == HttpURLConnection.HTTP_OK) {
inputStream = con.getInputStream();
} else {
inputStream = con.getErrorStream();
}
OutputStream output = new FileOutputStream("test.zip");
// Process the response
BufferedReader reader;
String line = null;
reader = new BufferedReader(new InputStreamReader(inputStream));
while ((line = reader.readLine()) != null) {
output.write(line.getBytes());
}
output.close();
inputStream.close();
Toute idée?
Vous ne devrait pas faire une URL avec 'reportInfo.getURI() toString()', 'utiliser reportInfo.getURI() toURL()' – greedybuddha