public String replaceAll(String ori, char regex, char replacement)
{
StringBuffer sb = new StringBuffer();
for (int i = 0; i < ori.length(); i++)
{
char c = ori.charAt(i);
if (c == regex)
{
c = replacement;
}
sb.append(c);
}
return sb.toString();
} public boolean upload(String source, String from, String to) {
boolean suc = false;
source = replaceAll(source, '\\', '/');
if (!source.startsWith("/")) {
source = "/" + source;
}
from = this.replaceAll(from, '\\', '/');
if (from.endsWith("/")) {
from = from.substring(0, from.length() - 1);
}
to = this.replaceAll(to, '\\', '/');
if (to.endsWith("/")) {
to = to.substring(0, to.length() - 1);
}
System.out.println(source + "\n" + from + "\n" + to);
try {
FileInputStream in = new FileInputStream(from + source);
int last = source.lastIndexOf("/");
//client.makeDirectory("aaaaaa");
System.out.println("store......" + to + source.substring(0, last));
this.makeDirectory(to + source.substring(0, last));
client.storeFile(to + source, in);
in.close();
suc = true;
} catch (FileNotFoundException ex) {
suc = false;
ex.printStackTrace();
} catch (IOException io) {
suc = false;
io.printStackTrace();
}
return false;
}
请高人不吝赐教!