How to copy file using FromFile in Struts java

public String copyFile(FormFile formFile, String destinationFolder,
            String outputFileName) throws IOException {

        byte[] data = new byte[1000];
       
        InputStream input = formFile.getInputStream();
        String filename = formFile.getFileName();
        new File(destinationFolder).mkdirs();
        File file = new File(destinationFolder, outputFileName);
        FileOutputStream output = new FileOutputStream(file);
        try {
            try {
                while (true) {
                    int count = input.read(data);
                    if (count == -1)
                        break;
                    output.write(data, 0, count);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            finally {
                input.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            output.close();
        }
        return filename;
    }

Comments

Recent Post

Recent Posts Widget

Popular posts from this blog

Capture image from webcam java code, examples

How to capture finger prints in java

Shallow Copy Deep Copy Java example