title: How to read and write data in same excel using poi and for loop
body: <p>I am using following code to read /write , ..
  I am able to read data but not able write data in it .</p>
  
  <pre><code> public class RWExcelPOI {
      File src=new File("D:\\Sujit\\Automated Script\\Auto_Tuto\\TestDataPOI.xlsx");
      XSSFWorkbook wb;
      XSSFSheet Sheet1;
      FileOutputStream fileOut;
  
      public void ReadExcel1() throws Exception{
  
  
          FileInputStream fis = new FileInputStream(src);
  
          XSSFWorkbook wb=new XSSFWorkbook(fis);
  
          XSSFSheet Sheet1=wb.getSheetAt(0);
  
  
          int rowcount=Sheet1.getPhysicalNumberOfRows();
          int colcount=Sheet1.getRow(0).getPhysicalNumberOfCells();
          System.out.println("Total Number of Rows is ::"+rowcount);
          System.out.println("Total number of Col is ::"+colcount);
  
          for(int i=0;i&lt;rowcount;i++){
  
  
              for(int j=0;j&lt;colcount;j++){
  
  
                  String testdata1=Sheet1.getRow(i).getCell(j).getStringCellValue();
                  System.out.println("Test data from excel cell  :"+testdata1);
                  wb.close();
  
  
                  Cell cell = null;  
                  cell = Sheet1.getRow(i).getCell(j);
  
                  cell.setCellValue("hmm");
                  // Write the output to a file  
                  FileOutputStream fileOut = new FileOutputStream(src);  
                  wb.write(fileOut); 
  
              }
  
          }
  
  
      }
  
      public static void main(String args[]) throws Exception{
  
          RWExcelPOI read=new RWExcelPOI();
          read.ReadExcel1();
  
  
  
      }
  </code></pre>
  
  <p>Please let me know where i am missing .
  My Excel sheet is like </p>
  
  <p>user 1 pswd 1 (I want to write in this column)
  user 2 pswd 2 (I want to write in this column)</p>
  
  <p>When i run my code my output is like :
  user 1 pswd 1
  user 2 pswd 2</p>
  
  <p>but when i open it overwrite previous data</p>