summaryrefslogtreecommitdiffstats
path: root/src/examples
diff options
context:
space:
mode:
authorGlen Stampoultzis <glens@apache.org>2004-09-22 00:42:43 +0000
committerGlen Stampoultzis <glens@apache.org>2004-09-22 00:42:43 +0000
commitb4ba64b1e14630a3cc4656e0b8822de54280e173 (patch)
tree4b1478cfe08b3795d54df783ae3edef2ff4db100 /src/examples
parent2735e662e9bb0d7106052d187213caa523ec5489 (diff)
downloadpoi-b4ba64b1e14630a3cc4656e0b8822de54280e173.tar.gz
poi-b4ba64b1e14630a3cc4656e0b8822de54280e173.zip
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
Diffstat (limited to 'src/examples')
-rw-r--r--src/examples/src/org/apache/poi/hssf/usermodel/examples/ReadWriteWorkbook.java45
1 files changed, 28 insertions, 17 deletions
diff --git a/src/examples/src/org/apache/poi/hssf/usermodel/examples/ReadWriteWorkbook.java b/src/examples/src/org/apache/poi/hssf/usermodel/examples/ReadWriteWorkbook.java
index 29658845a7..86f56ec73a 100644
--- a/src/examples/src/org/apache/poi/hssf/usermodel/examples/ReadWriteWorkbook.java
+++ b/src/examples/src/org/apache/poi/hssf/usermodel/examples/ReadWriteWorkbook.java
@@ -39,23 +39,34 @@ public class ReadWriteWorkbook
public static void main(String[] args)
throws IOException
{
- POIFSFileSystem fs =
- new POIFSFileSystem(new FileInputStream("workbook.xls"));
- HSSFWorkbook wb = new HSSFWorkbook(fs);
- HSSFSheet sheet = wb.getSheetAt(0);
- HSSFRow row = sheet.getRow(2);
- if (row == null)
- row = sheet.createRow(2);
- HSSFCell cell = row.getCell((short)3);
- if (cell == null)
- cell = row.createCell((short)3);
- cell.setCellType(HSSFCell.CELL_TYPE_STRING);
- cell.setCellValue("a test");
-
- // Write the output to a file
- FileOutputStream fileOut = new FileOutputStream("workbook.xls");
- wb.write(fileOut);
- fileOut.close();
+ FileInputStream fileIn = null;
+ FileOutputStream fileOut = null;
+ try
+ {
+ fileIn = new FileInputStream("workbook.xls");
+ POIFSFileSystem fs = new POIFSFileSystem(fileIn);
+ HSSFWorkbook wb = new HSSFWorkbook(fs);
+ HSSFSheet sheet = wb.getSheetAt(0);
+ HSSFRow row = sheet.getRow(2);
+ if (row == null)
+ row = sheet.createRow(2);
+ HSSFCell cell = row.getCell((short)3);
+ if (cell == null)
+ cell = row.createCell((short)3);
+ cell.setCellType(HSSFCell.CELL_TYPE_STRING);
+ cell.setCellValue("a test");
+
+ // Write the output to a file
+ fileOut = new FileOutputStream("workbook.xls");
+ wb.write(fileOut);
+ }
+ finally
+ {
+ if (fileOut != null)
+ fileOut.close();
+ if (fileIn != null)
+ fileIn.close();
+ }
}
}