public boolean copyFile(String fileSour, String fileAim) { try // must try and catch,otherwide will compile error { // instance the File as file_in and file_out File file_in = new File(fileSour); File file_out = new File(fileAim); FileInputStream in = new FileInputStream(file_in); FileOutputStream out = new FileOutputStream(file_out); byte[] bytes = new byte[1024]; int c; while ((c = in.read(bytes)) != -1) out.write(bytes, 0, c); in.close(); out.close(); return (true); // if success then return true } catch (IOException e) { log.error("IO Exception: " + e); return (false); // if fail then return false } }这个搞定 !!!!!
{
try
// must try and catch,otherwide will compile error
{
// instance the File as file_in and file_out
File file_in = new File(fileSour);
File file_out = new File(fileAim);
FileInputStream in = new FileInputStream(file_in);
FileOutputStream out = new FileOutputStream(file_out);
byte[] bytes = new byte[1024];
int c;
while ((c = in.read(bytes)) != -1)
out.write(bytes, 0, c);
in.close();
out.close();
return (true); // if success then return true
} catch (IOException e)
{
log.error("IO Exception: " + e);
return (false); // if fail then return false
}
}这个搞定 !!!!!
public ActionForward fileUpload(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws FileNotFoundException, IOException {
String filepath = "E:/111";
String toPath = "E:/222";
FileInputStream in = null;
FileOutputStream out = null;
File filedoc = new File(filepath);
if (!filedoc.isDirectory()) {
System.out.println(filepath + " not exists");
} else {
File filelist[] = filedoc.listFiles();
for (int i = 0; i < filelist.length; i++) {
File file = filelist[i];
in = file.getInputStream();
out = new FileOutputStream(toPath);
int read = 0;
byte[] buffer = new byte[8192];
while ((read = in.read(buffer, 0, 8192)) != -1) {
out.write(buffer, 0, read);
}
out.close();
in.close();
}
}
return mapping.findForward("fileUpload");
}