안드로이드 FTPClient 다운로드 업로드시 얼만큼 진행되었는지 퍼센트로 표시하는법
private void fileDownloadtest(final String strPath, final String strItem, final int i) {
VsrcFilePath = strPath;
VdesFilePath = FileUtil.FTPCLINET_LOCAL_DOWNLOAD + strItem;
mHandler.sendEmptyMessageDelayed(Percent,3000);
Thread mThread = new Thread(new Runnable() {
@Override
public void run() {
try {
boolean res = FTPManager.getInstance().ftpDownload(strPath + strItem, FileUtil.FTPCLINET_LOCAL_DOWNLOAD + strItem, i); //다운로드 하는곳
Thread를 써서 다운로드 받으면서 핸드러 쪽에서 퍼센트를 3초에 한번씩 출력하게 만들고 싶은데
핸들러에서 UpDownPercent2이 함수를 호출해서 실행하는데
100퍼센트가 되기전에 불러오면 오류가 나고 100퍼센트 되고나서 불러오면 100퍼센트라고 잘 나오는데
어떻게 해야 중간에 값들을 불러올수 있을까요?
String UpDownPercent2(String srcFilePath, String desFilePath, int downPos) {
// TODO Auto-generated method stub
FTPFile[] Fa = null;
// 퍼센트 용량 불러오기
try {
Fa = mFTPClient.listFiles(srcFilePath);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int a2 = (int) Fa[downPos-1].getSize();
String b = FileUtil.txtFileImformation(desFilePath);
int b2 = (int) Long.parseLong(b);
double percent = (double)((double)b2/(double)a2) * 100;
//Float percent = (float) ((a2/b2)*100);
String dispPattern = "0.##";
DecimalFormat form = new DecimalFormat(dispPattern);
percent = (int)Float.parseFloat(form.format(percent));
String per = String.valueOf(percent);
//this.totalBytesTransferred = totalBytesTransferred;
if(a2==b2)
{
PercentEnd = true;
}
return per;
}