0
所有有可能創建一個進度對話框來顯示線程下的上傳進度,我使用這段代碼上傳一個名爲index.html的文件爲ftp。 請提前幫助我thanx。將進度對話框添加到storefile();
new Thread(new Runnable() {
public void run() {
Looper.prepare();
FTPClient client = new FTPClient();
try {
boolean result = false;
FileInputStream fis = null;
client.connect(server);
client.enterLocalPassiveMode();
client.login(user, pass);
client.makeDirectory("/public_html/"+str);
client.setFileType(FTP.BINARY_FILE_TYPE);
client.setFileTransferMode(FTP.BINARY_FILE_TYPE);
client.changeWorkingDirectory(str);
String path1 = Environment.getExternalStorageDirectory() + "/index.htm";
File f = new File(path1);
String testname = "/public_html/"+str+"/"+f.getName();
fis = new
FileInputStream(f);
result = client.storeFile(testname, fis);
if (result == true){
Log.v("upload","upload successfull");
}
else{
Log.v("upload", "upload failed");
}
client.logout();
client.disconnect();
}
catch (Exception e) {
Context context = getApplicationContext();
CharSequence text = "failed!!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
}
}).start();
我想上傳一個文件不下載 –
從android 1.6開始,最多可以有5個併發的asynctasks – SemaphoreMetaphor
請給我一個上傳文件的代碼,不要下載進度條, thanx回答 –