-4
File src = new File(filePath);
FileInputStream fis = new FileInputStream(src);
XSSFWorkbook wb = new XSSFWorkbook(fis);
XSSFSheet sheet1 = wb.getSheetAt(0);

Why did they pass the src object to FileInputStream?

Why did they pass FileInputStream object to xssfworkbook?

Why they did'nt pass any objects for xssfsheet?

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
Manoj Kumar
  • 93
  • 1
  • 3
  • 11
  • Have you read the appropriate documentation? I'd imagine that tells you what parameters the constructors and methods take. – jonrsharpe Jan 19 '18 at 12:08
  • 2
    This is how workbooks and sheets are typically initiated in POI. The workbook needs a FileInputStream to read from, etc. Next step would be to call methods in sheet1 to read/write information. There are plenty of tutorials out there. – Stefan Jan 19 '18 at 12:10
  • Because the relevant docs say so. – luk2302 Jan 19 '18 at 12:16

2 Answers2

1

Just for fun. Key idea is reading docs and learning language

File src = new File(filePath);

Java File class represents the files and directory pathnames in an abstract manner. This class is used for creation of files and directories, file searching, file deletion, etc. https://www.tutorialspoint.com/java/java_file_class.htm

FileInputStream fis = new FileInputStream(src);

A FileInputStream obtains input bytes from a file in a file system. What files are available depends on the host environment. https://docs.oracle.com/javase/7/docs/api/java/io/FileInputStream.html

XSSFWorkbook wb = new XSSFWorkbook(fis);

High level representation of a SpreadsheetML workbook. This is the first object most users will construct whether they are reading or writing a workbook. It is also the top level object for creating new sheets/etc. https://poi.apache.org/apidocs/org/apache/poi/xssf/usermodel/XSSFWorkbook.html

XSSFSheet sheet1 = wb.getSheetAt(0);

Get the XSSFSheet object at the given index. https://poi.apache.org/apidocs/org/apache/poi/xssf/usermodel/XSSFWorkbook.html

vadzim dvorak
  • 939
  • 6
  • 24
0

Why did they pass the src object to FileInputStream?

Because FileInputStream will need a File to instantiate. src is an instance of File.

Why did they pass FileInputStream object to xssfworkbook?

Because XSSFWorkbook needs a FileInputStream to instantiate. fis is a FileInputStream.

Why they did'nt pass any objects for xssfsheet?

Because the sheet can be retrieved from wb using getSheetAt.

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175