Upload into system folder using jsf2.0

别说谁变了你拦得住时间么 提交于 2019-12-24 21:33:13

问题


I am new to jsf frame work.I am using jsf2.0 in eclipse ide.I have try to upload a images in jsf2.0.I have uploaded the image but it stored on eclipse server.The problem is when i clean the server the images are deleted.So i need a help,to upload photo into system local folder.please find and help me.

    public void processFileUpload(FileUploadEvent event) throws    AbortProcessingException {



   System.out.println("Uploaded: " +event.getFile().getFileName());
   UploadedFile file = event.getFile();
   byte[] readData=file.getContents();
   dosyaisim=file.getFileName();
   System.out.println("GHFGHGH"+dosyaisim);
   imgSave(readData,dosyaisim);

   FacesMessage msg = new FacesMessage("Succesful", event.getFile().getFileName() + " is  uploaded.");
   FacesContext.getCurrentInstance().addMessage(null, msg);
  }
   public void imgSave( byte[] readData,String dosyaisim )
  {
  try {
  ExternalContext extContext=FacesContext.getCurrentInstance().getExternalContext();
  FileOutputStream fos = new FileOutputStream("images"+dosyaisim);
  System.out.println("IMAGE PATH="+fos);

  String relativeWebPath = "e:/Images";
  String absoluteDiskPath = extContext.getRealPath(relativeWebPath);

ERROR OCCURING IS:

   java.io.IOException: The filename, directory name, or volume label syntax is incorrect
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.checkAndCreate(File.java:1704)
at java.io.File.createTempFile(File.java:1792)
at image.MyBean.imgSave(MyBean.java:59)
at image.MyBean.processFileUpload(MyBean.java:41)

回答1:


You were specifying a wrong file path in FileOutputStream. Fix it as follows:

FileOutputStream fos = new FileOutputStream("e:/Images/images" + dosyaisim);
// Now write InputStream to it.

You don't need ExternalContext#getRealPath() at all.



来源:https://stackoverflow.com/questions/8020156/upload-into-system-folder-using-jsf2-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!