1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| private static final int BUFFER_SIZEE = 6124;
public void handleFileUpload(FileUploadEvent event, String chemin) {
File result = new File(chemin);
try {
FileOutputStream fileOutputStream = new FileOutputStream(result);
byte[] buffer = new byte[BUFFER_SIZEE];
int bulk;
InputStream inputStream = event.getFile().getInputstream();
while (true) {
bulk = inputStream.read(buffer);
if (bulk < 0) {
break;
}
fileOutputStream.write(buffer, 0, bulk);
fileOutputStream.flush();
}
fileOutputStream.close();
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
FacesMessage error = new FacesMessage(FacesMessage.SEVERITY_ERROR,
" the files were not uploaded!", "");
FacesContext.getCurrentInstance().addMessage(null, error);
}
}
public String saveProduit(){
String chem="C:\\env_dev\\Site_Web_De_Vente_En_Ligne\\WebContent\\images\\"+nvProduit.getPhoto();
handleFileUpload(img, chem);.... |
Partager