I have two classes one contains the method fileupload and save file ... I want from MB to call this class, which is the most correct way

1

follows the class fileupload

public class FileUpload{

private String destination="D:\tmp\";

public void upload(FileUploadEvent event) {  
    FacesMessage msg = new FacesMessage("Success! ", event.getFile().getFileName() + " is uploaded.");  
    FacesContext.getCurrentInstance().addMessage(null, msg);
    // Do what you want with the file        
    try {
        copyFile(event.getFile().getFileName(), event.getFile().getInputstream());
    } catch (IOException e) {
        e.printStackTrace();
    }

}  

public void copyFile(String fileName, InputStream in) {
       try {


            // write the inputStream to a FileOutputStream
            OutputStream out = new FileOutputStream(new File(destination + fileName));

            int read = 0;
            byte[] bytes = new byte[1024];

            while ((read = in.read(bytes)) != -1) {
                out.write(bytes, 0, read);
            }

            in.close();
            out.flush();
            out.close();

            System.out.println("New file created!");
            } catch (IOException e) {
            System.out.println(e.getMessage());
            }
}

I want to call this method doUpload of my ManagedBean , it is in a separate package because it will be reused several times

@managedBean
public class MBminhaTela{

chamar objeto doUpload da classe FileUpload

}
    
asked by anonymous 06.09.2015 / 15:18

0 answers