1. 程式人生 > >java的http協議檔案上傳 (一)

java的http協議檔案上傳 (一)

//把上傳檔案存放到指定的目錄下檔名
private void saveAs(File upFile, String filePath) throws IOException {
  FileInputStream fis = null;
  FileOutputStream fos = null;
  try {
   fis = new FileInputStream(upFile);
   int len = fis.available();
   byte[] by = new byte[len];
   fis.read(by);
   fos = new FileOutputStream(filePath);
   fos.write(by);
  }
  finally {
   if (fos != null)
    fos.close();
   if (fis != null)
    fis.close();
  }
 }