日期:2014-05-20 浏览次数:20888 次
public boolean uploadFile(String RWFileDir,String filepathname,String filename) { boolean result=true; String message = ""; String name =""; if (aftp.serverIsOpen()) { System.out.println("正在上传文件"+filepathname+",请等待...."); try { name = new String(filename.getBytes("UTF-8")); RandomAccessFile sendFile = new RandomAccessFile(filepathname,"r"); sendFile.seek(0); outs = aftp.put(name); outputs = new DataOutputStream(outs); while (sendFile.getFilePointer() < sendFile.length() ) { ch = sendFile.read(); outputs.write(ch); } outputs.flush(); message = "上传"+filepathname+"文件成功!"; System.out.println(message); outputs.close(); outs.close(); sendFile.close(); log(RWFileDir,message); //记录日志 } catch(IOException e) { message = "上传"+filepathname+"文件失败!"+e; System.out.println(message); log(RWFileDir,message); result = false ; } } else { result = false; } return result; }