这一个是和上面一起的,因为没有办法发这么多所以我拆成两次
public boolean uploadfile(String rwfiledir, String filepathname) {
boolean result = true;
String message = "";
if (aftp != null) {
System.out.println("正在上传文件" + filepathname + ",请等待...."); try {
String fg = new String("\\subunsubfromsp\\");
int index = filepathname.lastIndexOf(fg);
String filename = filepathname.substring(index + 1);
File localfile = new File(filepathname); RandomAccessFile sendfile = new RandomAccessFile(filepathname,
"r");
// 
sendfile.seek(0);
// 改名上传temp_
filename = filename.substring(0, 15) + "temp_"
+ filename.substring(15, filename.length());
outs = aftp.put(filename);
outputs = new DataOutputStream(outs);
while (sendfile.getFilePointer() < sendfile.length()) {
ch = sendfile.read();
outputs.write(ch);
} rename(filename.substring(15, filename.length()), filename
.substring(20, filename.length()));
outs.close();
sendfile.close(); message = "上传" + filepathname + "文件成功!";
System.out.println(message);
log(rwfiledir, message);
} catch (IOException e) {
message = "上传" + filepathname + "文件失败!" + e;
System.out.println(message);
log(rwfiledir, message); result = false; }
} else {
result = false;
}
return result;
} public void rename(String oldname, String newname) { // aftp.renameto(oldname,newname);
File old = new File(oldname); // oldname
File new1 = new File(newname); // newname
// aftp.renameto(new);
// boolean old.renameto(file newname);
// System.out.println(old);
// System.out.println(new); } public static void delefile(String rwfiledir) {
// try {
// 取得readfile目录下的txt文件
String sdir = rwfiledir + "subunsubfromsp\\";
File fdir = new File(sdir);
String filename = "";
int j = fdir.list().length; System.out.println(sdir + "目录下要删除的文件数:" + fdir.list().length);
File file;
for (int i = 0; i <= 100; i++) {
// 删除subunsubfromsp中的txt文件
filename = rwfiledir + "subunsubfromsp\\" + (fdir.list())[0];
file = new File(filename);
file.delete();
System.out.println("已经成功删除" + filename + "文件!");
}
// }
// catch (ioexception e) {
// System.out.println("删除txt文件错误!");
// e.printstacktrace();
// }
} public void showfilecontents(String strdir) {
StringBuffer buf = new StringBuffer();
try {
aftp.cd(strdir);
ins = aftp.list();
while ((ch = ins.read()) >= 0) {
buf.append((char) ch);
} System.out.println(buf.toString()); ins.close();
} catch (IOException e) {
}
} // 返回当前目录的所有文件及文件夹 public ArrayList getfilelist() throws IOException {
BufferedReader dr = new BufferedReader(new InputStreamReader(aftp
.list()));
ArrayList al = new ArrayList();
String s = "";
while ((s = dr.readLine()) != null) {
al.add(s);
}
return al;
} public void setpath(String path) throws IOException {
if (aftp == null)
this.path = path;
else {
aftp.cd(path);
}
} // 返回当前目录的文件名称 public ArrayList getnamelist(String rwfiledir) throws IOException { BufferedReader dr = new BufferedReader(new InputStreamReader(aftp
.nameList("subunsubtosp\\")));
ArrayList al = new ArrayList();
String s = "";
while ((s = dr.readLine()) != null) {
al.add(s);
s = s.substring(13, s.length());
isfile(s);
downloadfile(rwfiledir, s);
// String strfiledelf = aftp.namelist("subunsubtosp\\");
File filedelf = new File(s);
filedelf.delete();
}
return al;
// System.out.println(al.add(s));
} // 判断一行文件信息是否为目录 public boolean isdir(String line) {
return ((String) parseline(line).get(0)).indexOf("d") != -1;
} public boolean isfile(String line) {
return !isdir(line);
} // 处理getfilelist取得的行信息 private ArrayList parseline(String line) {
ArrayList s1 = new ArrayList();
StringTokenizer st = new StringTokenizer(line, " ");
while (st.hasMoreTokens()) {
s1.add(st.nextToken());
}
return s1;
}
}