String path = ServletActionContext.getServletContext().getRealPath("upload/"+pic[j]);

File file = new File(path);file.delete();这个路径删除不了?
请问必须要绝对路径吗?

解决方案 »

  1.   

    将 path 打印出来 检查一下  生成的  路径是否有问题
      

  2.   

    需要绝对路径,你删除前先看看文件是否存在:if(file.exists())file.delete()
      

  3.   


    String path = ServletActionContext.getServletContext().getRealPath("upload/"+pic[j]);File file = new File(path);
    结果: file not esist 
    如何得到绝对路径
      

  4.   

    String path = ServletActionContext.getServletContext().getRealPath("/upload/"+pic[j]);
    这样试试
      

  5.   

    楼主可以通过path 自己去找找看看是否可以找到指定需删除的文件
      

  6.   


    String path = ServletActionContext.getServletContext().getRealPath("upload/"+pic[j]);File file = new File(path);
    结果: file not esist 
    如何得到绝对路径
      

  7.   


    这貌似不行,
    D:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ToyTa\upload\1284974866119.jpg
    这个是path,如果写绝对路径应该是:D://xxx//xxx或者 D:\\xxx\\xxx
    我想是不是这个原因呢
      

  8.   

    杯具了,很抱歉各位,项目的中存放路径改成了UploadImg,而我还用upload, so sorry
    感谢各位。