我能够获取你要上传文件的名字,那怎么样子去获取现在上传的目录里的名字。也就是说,假如我现在要上传一个叫“struts文件上传资料.doc”这个文件,那怎么样子去验证我现在的那个目录有没有也有一个叫这样子名字的文件,如果有的话,就给我一个错误的提示,说目录里已经有这样子的名字,如果没有的话就可以顺利上传。大家说一下,你们做上传 是怎么样子做的?是怎么样子去命名那上传的文件的名字。假如我现在上传的时候就年月日时分秒这样子来命名的话,那到时下载的时候,怎么样子下载回你那时上传的时候的那个名字呢?如果大家有谁做了一个好的struts 1.x文件上传及下载的例子,能否借鉴下,如果可以的话,请发给][email protected][/email]  谢谢

解决方案 »

  1.   

    共享了份 struts1.2 上传文件源码至 csdn 资源,楼主可以去看看,参考下
      

  2.   

    java有专门的类判断目录下是否有没有某个文件的。你去查一下。判断的时候如果没有和你要传的文件同名的,就直接上传。
    有就在文件名的后面加上当前时间,防止重复。
      

  3.   

    下面是jdk6.0.03的源码中java.io.File的exist方法..
    这个方法可以判断你这个文件是否存在.
        /**
         * Tests whether the file or directory denoted by this abstract pathname
         * exists.
         *
         * @return  <code>true</code> if and only if the file or directory denoted
         *          by this abstract pathname exists; <code>false</code> otherwise
         *
         * @throws  SecurityException
         *          If a security manager exists and its <code>{@link
         *          java.lang.SecurityManager#checkRead(java.lang.String)}</code>
         *          method denies read access to the file or directory
         */
        public boolean exists() {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkRead(path);
    }
    return ((fs.getBooleanAttributes(this) & FileSystem.BA_EXISTS) != 0);
        }
      

  4.   

    File 来检查这个文件是否存在。