1
follows the fileupload class
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
}
Have you checked the showcase how to do?
– Macario1983
the method is direct in managedBean what I want is to call this method a useful package
– Sandro Costa
Okay, this method will be static?
– Macario1983
would be the best way to call him
– Sandro Costa
If I understand, right you want to call the method a static class within the mbMinhaTela class correct? If it is, just call the method...
– Macario1983