The process cannot access the file because it is being used by another process
<p>I am trying to read data from one sheet of excel file and write to other sheet of same excel file.I have tried this :</p>

<pre><code>FileInputStream file = new FileInputStream(new File("E:\\excel\\input.xlsx"));
            //Create Workbook instance holding reference to .xlsx file
            XSSFWorkbook workbook = new XSSFWorkbook(file);
            //Get first/desired sheet from the workbook
            XSSFSheet sheet = workbook.getSheetAt(0);
            //Iterate through each rows one by one
            Iterator&lt;Row&gt; rowIterator = sheet.iterator();
            while (rowIterator.hasNext()) 
            {
                Row row = rowIterator.next();
                //For each row, iterate through all the columns
                Iterator&lt;Cell&gt; cellIterator = row.cellIterator();
                while (cellIterator.hasNext()) 
                {
                    Cell cell = cellIterator.next();
                    //Check the cell type and format accordingly
                    switch (cell.getCellType()) 
                    {
                    case Cell.CELL_TYPE_NUMERIC:
                        System.out.print((int)cell.getNumericCellValue()+ "       ");
                        break;
                    case Cell.CELL_TYPE_STRING:
                        System.out.print(cell.getStringCellValue());
                        break;
                    }
                }
                System.out.println("");
            }
            file.close();
            CreationHelper createHelper = workbook.getCreationHelper();
            XSSFSheet newSheet = workbook.createSheet("new sheet");
            // Create a row and put some cells in it. Rows are 0 based.
            Row row = newSheet.createRow((short)0);
            // Create a cell and put a value in it.
            Cell cell = row.createCell(0);
            cell.setCellValue(1);
            // Or do it on one line.
            row.createCell(1).setCellValue(1.2);
            row.createCell(2).setCellValue(
                    createHelper.createRichTextString("This is a string"));
            row.createCell(3).setCellValue(true);
            System.out.println("writing to file");
            // Write the output to a file
            FileOutputStream fileOut = new FileOutputStream(new File("E:\\excel\\input.xlsx"));
            workbook.write(fileOut);
            fileOut.close();
</code></pre>

<p>I have successfully read data from excel sheet But I am getting exception while writing in new sheet given below </p>

<pre><code>java.io.FileNotFoundException: E:\excel\input.xlsx (The process cannot access the file because it is being used by another process)
</code></pre>