通过apache的common-net.jar写的ftp上传,上传后的图片都不能用,请教各位大虾如何解决?老弟跪求了!

zxmzfbdc 2005-06-14 12:13:46
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;
}


请高人不吝赐教!
...全文
223 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
曼绕木杉 2005-06-15
  • 打赏
  • 举报
回复
用FTPClient.setFileType(FTPClient.IMAGE_FILE_TYPE)就可以了。
zxmzfbdc 2005-06-15
  • 打赏
  • 举报
回复
顶!
laughsmile 2005-06-15
  • 打赏
  • 举报
回复
client没有声明啊,client.storeFile(to + source, in);是什么?
goingon99 2005-06-14
  • 打赏
  • 举报
回复
为什么不用smartuploader,在家都用它,试试吧,据说不错

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧