通过URL获取文件的大小

时间:2025-04-27 10:37:17
/**
 * get file properties
 * 获取文件的信息
 * @author Mike
 *
 */
public class FileOperation {
 
 /**
  * get file size 通过URL地址获取文件大小
  * @param filePath * url file path
  * @return filesize
  * @throws MalformedURLException
  */
 public static String getFileSize(String filePath) throws MalformedURLException{
  HttpURLConnection urlcon = null;
  String size="";
  //format double
   fnum = new ("#0.000");
  //create url link
  URL url=new URL(filePath);
  try {
   //open url
   urlcon = (HttpURLConnection)();
   //get url properties
   double filesize=();
   //format output
   size=(filesize/1024);
  } catch (IOException e) {
   ();
  } finally{
   //close connect
   ();
  }
  return size;
 }