Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private String uploadFile(UploadedFile doc) {
- UploadedFile myDoc = doc;
- String path = null;
- if (myDoc != null) {
- String fileName = myDoc.getFilename();
- String uploadedFileName = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(new Date()) + "_" + fileName;
- path = FILE_PATH + uploadedFileName;
- System.out.println(path + " PATH + FILENAME ");
- InputStream inputStream = null;
- File file;
- try {
- URL pathURL = new URL(path);
- try {
- file = new File(pathURL.toURI());
- } catch (URISyntaxException e) {
- file = new File(pathURL.getPath());
- }
- FileOutputStream out = new FileOutputStream(file);
- inputStream = myDoc.getInputStream();
- byte[] buffer = new byte[8192];
- int bytesRead = 0;
- while ((bytesRead = inputStream.read(buffer, 0, 8192)) != -1) {
- out.write(buffer, 0, bytesRead);
- }
- out.flush();
- out.close();
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- } finally {
- try {
- if (null != inputStream)
- inputStream.close();
- } catch (IOException ioex) {
- log.error(ioex.getMessage(), ioex);
- }
- }
- }
- return path;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement