文件的大小,我有以下方法來確定文件大小:機器人不能從對話框
public static long getSize(String path) {
File file = new File(path);
if (file.exists()) {
long size = file.length();
return size;
} else {
Log.e("zero size", "the file size is zero!");
return 0;
}
現在我想說明以下方法(代碼是不完整)的對話:
public void gimmeDialog(String path_to_file) {
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.dialog);
dialog.setTitle("Confirm");
TextView text = (TextView) dialog.findViewById(R.id.txtUploadInfo);
Button dialogButtonOK = (Button) dialog.findViewById(R.id.btnDialogOK);
long uploadSize = Send.getSize(path_to_file)/1024/1024;
text.setText("You are about to upload "
+ Long.toString(uploadSize)
+ " MB. You must accept the terms of service before you can proceed");
dialogButtonOK.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
問題是uploadSize始終爲零,雖然getSize()方法在對話框函數外調用時返回正確的文件大小。給定的字符串路徑是正確的。可能是什麼原因?
P.S.發送是我的課程名稱
是你的文件更大然後1 MB? –