2014-07-22 4 views
0

파일을 업로드 할 건물 서비스를 위해 저지를 사용하고 있습니다. 하지만 필요한 위치에 파일을 쓰는 데 문제가 있습니다. Java throws 시스템이 지정된 경로 오류를 찾을 수 없습니다. 여기 내 웹 서비스 : (그것은 예외 스택 추적을 포함하는 것이 도움이) 코드 만보고에서Jersey 휴식 서비스를 사용하여 파일을 업로드하는 중 오류가 발생했습니다.

@POST 
    @Path("/fileupload") 
    @Consumes(MediaType.MULTIPART_FORM_DATA) 
    public Response uploadFile(@FormDataParam("file")InputStream fileUploadStream, @FormDataParam("file")FormDataContentDisposition fileDetails) throws IOException{ 

     StringBuilder uploadFileLocation= new StringBuilder(); 

      uploadFileLocation.append("c:/logparser/webfrontend/uploads"); 
     uploadFileLocation.append("/"+dateFormat.format(Calendar.getInstance().getTime())); 
     uploadFileLocation.append("/"+fileDetails.getFileName()); 
     writeToFile(fileUploadStream, uploadFileLocation.toString()); 
     return Response.status(200).entity("File saved to " + uploadFileLocation).build(); 
    } 

    private void writeToFile(InputStream uploadInputStream, String uploadFileLocation) 
    { 
     log.debug("UploadService , writeToFile method , start()"); 

     try{ 
      int read = 0; 
      byte[] bytes = new byte[uploadInputStream.available()]; 

      log.info("UploadService, writeToFile method , copying uploaded files."); 
     OutputStream out = new FileOutputStream(new File(uploadFileLocation)); 
      while ((read = uploadInputStream.read(bytes)) != -1) 
      { 
       out.write(bytes, 0, read); 
      } 
      out.flush(); 
      out.close(); 
     } 
     catch(Exception e) 
     { 
      log.error("UploadService, writeToFile method, error in writing to file "+e.getMessage()); 
     } 
    } 

답변

0

, 당신은 존재하지 않는 타임 스탬프에 따라 디렉토리에 쓰기를 시도하고 아직. File.mkdir/mkdirs에 대한 호출을 추가하십시오. 이 질문을 보려면/대답 : FileNotFoundException (The system cannot find the path specified)

사이드 노트 - 내가하지 않는 이유가 없다면, 나는 아파치 commons-io (FileUtils.copyInputStreamToFile)와 같은 것을 쓰는 것을 고려할 것입니다.

관련 문제