Even though this is just a simple example it's probably not a good idea to not close the streams correctly.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353602 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6bfe3dc2b9
commit
ccee8a80af
@ -39,8 +39,13 @@ public class ReadWriteWorkbook
|
|||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
POIFSFileSystem fs =
|
FileInputStream fileIn = null;
|
||||||
new POIFSFileSystem(new FileInputStream("workbook.xls"));
|
FileOutputStream fileOut = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
fileIn = new FileInputStream("workbook.xls");
|
||||||
|
POIFSFileSystem fs = new POIFSFileSystem(fileIn);
|
||||||
HSSFWorkbook wb = new HSSFWorkbook(fs);
|
HSSFWorkbook wb = new HSSFWorkbook(fs);
|
||||||
HSSFSheet sheet = wb.getSheetAt(0);
|
HSSFSheet sheet = wb.getSheetAt(0);
|
||||||
HSSFRow row = sheet.getRow(2);
|
HSSFRow row = sheet.getRow(2);
|
||||||
@ -53,9 +58,15 @@ public class ReadWriteWorkbook
|
|||||||
cell.setCellValue("a test");
|
cell.setCellValue("a test");
|
||||||
|
|
||||||
// Write the output to a file
|
// Write the output to a file
|
||||||
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
|
fileOut = new FileOutputStream("workbook.xls");
|
||||||
wb.write(fileOut);
|
wb.write(fileOut);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (fileOut != null)
|
||||||
fileOut.close();
|
fileOut.close();
|
||||||
|
if (fileIn != null)
|
||||||
|
fileIn.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user