public static void main(String[] args) {

  File file = new File("D://123.xlsx");
  try {
    InputStream is = new FileInputStream(file);
    Workbook wb = null;
    if (file.getName().endsWith("xls")) { //Excel 2003
      try {
        wb = new HSSFWorkbook(is);
      } catch (IOException e) {
        e.printStackTrace();
      }
    } else if(file.getName().endsWith("xlsx")) { // Excel 2007/2010
      try {
        wb = new XSSFWorkbook(is);
      } catch (IOException e) {
        e.printStackTrace();
      }   
    }

    for (Sheet sheet : wb) {
      for (Row row : sheet) {
        StringBuffer sb = new StringBuffer();
        for (Cell cell : row) {
          sb.append(cell.toString());
        }
        System.out.println(sb);
      }
    }
  } catch (FileNotFoundException e) {
    e.printStackTrace();
  }
}