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 34 35 36 37 38 39 40
| public void run() {
//Téléchargement du fichier
public void getFile(Url u) throws IOException{
URL u = new URL("http://www.mysite.com/BDSQLite/mybase");
URLConnection uc = u.openConnection();
uc.setUseCaches(true);
int FileLenght = uc.getContentLength();
if (FileLenght == -1){
Toast.makeText(miseAjour.this, "Erreur de chargement", 1000).show();
{
try
}
InputStream myInput = uc.getInputStream();
String outFileName="/data/data/com.van.myappli/mybase";
FileOutputStream myOutPut = new myOutPut(outFileName);
byte[] buff = new byte[1024];
int I = myInput.read(buff);
while(I>0)
{
myOutPut.write(buff, 0, I);
I = myInput.read(buff);
}
myOutPut.flush();
myOutPut.close();
{
catch(Exception e)
}
Toast.makeText(miseAjour.this, e.toString, 1000).show();
}
}
//Télécharement terminé
handler.sendEmptyMessage(0);
}
private Handler handler = new Handler() {
public void handleMessage(Message msg) {
Toast.makeText(miseAjour.this, "Chargement terminé ...", 1000).show();
dialog.dismiss();
}
};
} |