super(stream);
}
+ /**
+ * <p>Creates a POIFSFileSystem from a <tt>File</tt>. This uses less memory than
+ * creating from an <tt>InputStream</tt>.</p>
+ *
+ * <p>Note that with this constructor, you will need to call {@link #close()}
+ * when you're done to have the underlying file closed, as the file is
+ * kept open during normal operation to read the data out.</p>
+ * @param readOnly whether the POIFileSystem will only be used in read-only mode
+ *
+ * @param file the File from which to read the data
+ *
+ * @exception IOException on errors reading, or on invalid data
+ */
+ public POIFSFileSystem(File file, boolean readOnly) throws IOException {
+ super(file, readOnly);
+ }
+
/**
* <p>Creates a POIFSFileSystem from a <tt>File</tt>. This uses less memory than
* creating from an <tt>InputStream</tt>. The File will be opened read-only</p>
tmp.close();
// Open it up again backed by the file
- return new POIFSFileSystem(file);
+ return new POIFSFileSystem(file, false);
}
/**
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.RecordFormatException;
import org.apache.poi.util.TempFile;
+import org.junit.Ignore;
import org.junit.Test;
import junit.framework.AssertionFailedError;
assertEquals(1, wb.getNumberOfSheets());
assertEquals("Changed!", wb.getSheetAt(0).getRow(0).getCell(0).toString());
}
+
+ @Test
+ @Ignore("Not currently working, bug in POIFS creating empty FS")
+ public void testWriteToNewFile() throws Exception {
+ // Open from a Stream
+ HSSFWorkbook wb = new HSSFWorkbook(
+ POIDataSamples.getSpreadSheetInstance().openResourceAsStream("SampleSS.xls"));
+
+ // Save to a new temp file
+ final File file = TempFile.createTempFile("TestHSSFWorkbook", ".xls");
+ wb.write(file);
+ wb.close();
+
+ // Read and check
+ wb = new HSSFWorkbook(new NPOIFSFileSystem(file));
+ assertEquals(3, wb.getNumberOfSheets());
+ wb.close();
+ }
}