0

ファイルのアップロードに関して問題があります。自分でファイルをアップロードすると(localhost)、実際には機能しますが、同じネットワーク内の他の人にファイルをアップロードさせると、エラーが発生します:

(The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:120)
at sources.UploadAIP.actions.uploadAction.processRequest(uploadAction.java:49)

これが私の実際のコードです:

public class uploadAction extends AbstractAppAction
{
   public boolean processRequest(HttpServlet servlet, HttpServletRequest request,    HttpServletResponse response)
   {
     try{
         Properties appProperties = getAppProperties();
         String dbMap = appProperties.getProperty("dbMap");
         DB db = getDBConnection(dbMap);

         String myDirectory = "C:\\tmp";
         String uploadedFile = request.getParameter("filename");
         System.out.println("srcfile: " +myDirectory);
         System.out.println("file: " +uploadedFile);
         String errorMessage = "";

         ServletContext sc       = servlet.getServletContext();
         String fileName         = StringUtil.stringReplace(uploadedFile,"\\","\\");
         int i                   = fileName.lastIndexOf("\\");
         if (i > 0) { 
              fileName   = fileName.substring(i+1); 
         }

         File srcFile            = new File(uploadedFile);
         File targetDirectory    = new File(myDirectory);
         String dirname          = StringUtil.stringReplace(targetDirectory.toString() ,"\\","\\");
         System.out.println("directory name:" +dirname);
         File destFile           = new File(dirname+"\\"+fileName);
         System.out.println(destFile);
         System.out.println("here is the parent directory: " +targetDirectory);    
         if(!targetDirectory.exists()){
              targetDirectory.mkdirs();
         }
         InputStream inStream;
         OutputStream outStream;
         try{
             inStream = new FileInputStream(srcFile);
         outStream = new FileOutputStream(destFile);
             byte[] buffer = new byte[4096];
         int length;
         //copy the file content in bytes
         while ((length = inStream.read(buffer)) > 0){
                  outStream.write(buffer, 0, length);
         }
         outStream.close();
         }catch(Exception e){
             e.printStackTrace();
         }
         fileName = StringUtil.stringReplace(uploadedFile, "\\", "\\");

          int u = fileName.lastIndexOf("\\");
          if (u > 0)
          {
            fileName = fileName.substring(i + 1);
          }

          if (!dirname.endsWith("\\"))
          {
           dirname = dirname + "\\";
          }

          File f = new File(dirname);
          String uploadDir = dirname;
          System.out.println("uploadDirectory" +uploadDir);


     } catch (Exception ex) {
        request.setAttribute("message", ex.toString());
        ex.printStackTrace();

    }
    return (true);
}

}

4

1 に答える 1