Téléchargement fichier texte
Bonjour ,
je souhaite télécharger un fichier texte depuis un server mais je me retrouve face à des exceptions. voici mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| public void getFile(URL url) throws IOException
{
try {
URLConnection connection = url.openConnection();
connection.connect();
int fileLength = connection.getContentLength();
// download the file
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream("/sdcard/file_name.extension");
byte data[] = new byte[1024];
long total = 0;
int count;
while ((count = input.read(data)) != -1) {
total += count;
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
}
catch (Exception e)
{
System.out.println(e);
}
} |
a caque fois je passe dans cette exception :
Code:
1 2 3 4
| catch (Exception e)
{
System.out.println(e);
} |
Je suis sur un projet Android et j'ai specifife les bonnes autorisations dans mon fichier manifest :
Citation:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
quelqu'un pourrait t'il m'aider ?
Merci d'avance