I do not know the answer to your question but I would like to discover just
what type of stream you are getting back when you call the
getResourceAsStream() method. If you have the time, it may be worth adding a
System.out.println(inputStream.getClass().getName()); statement just to see
what you are actually getting back; something like;

if (sourcePath == null){
    inputStream =
getClass().getClassLoader().getResourceAsStream("file.xls");
    System.out.println(inputStream.getClass().getName());
    workbook = WorkbookFactory.create(inputStream);
}

Also - and I admit that there is no reason why you would need to do this -
you could try wrapping up that input stream into a FileInputStream just,
again, to see what happens.

Yours

Mark B


individuodk wrote:
> 
> hi!!
> poi-3.5-FINAL.jar
> 
> 
>                       if (sourcePath == null){
>                               inputStream =
> getClass().getClassLoader().getResourceAsStream("file.xls");
>                               workbook = WorkbookFactory.create(inputStream);
>                       }
>                       else{
>                               inputStream = new FileInputStream(sourcePath);
>                               workbook = WorkbookFactory.create(inputStream);
>                       }
> 
> When i read excel file from FileInputStream to modify it, all works fine.
> When i read excel file (SAME excel file) from
> getClass().getClassLoader().getResourceAsStream..., all are exceptions
> like next:
> 
> convertPOIOutputStream|null|Exception||4|5|N| [ java.io.IOException ]
> block[ 63 ] already removed -
> does your POIFS have circular or duplicate block
> references?java.io.IOException: block[ 63 ] already
>  removed - does your POIFS have circular or duplicate block references?
>         at
> org.apache.poi.poifs.storage.BlockListImpl.remove(BlockListImpl.java:89)
>         at
> org.apache.poi.poifs.storage.RawDataBlockList.remove(RawDataBlockList.java:32)
>         at
> org.apache.poi.poifs.storage.BlockAllocationTableReader.fetchBlocks(BlockAllocationTableR
> eader.java:187)
>         at
> org.apache.poi.poifs.storage.BlockListImpl.fetchBlocks(BlockListImpl.java:123)
>         at
> org.apache.poi.poifs.storage.RawDataBlockList.fetchBlocks(RawDataBlockList.java:32)
>         at
> org.apache.poi.poifs.filesystem.POIFSFileSystem.processProperties(POIFSFileSystem.java:54
> 1)
>         at
> org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:176)
> 
> 
> or
> 
> convertPOIOutputStream|null|Exception||4|5|N| [
> org.apache.poi.hssf.record.RecordFormatException ] U
> nable to construct record
> instanceorg.apache.poi.hssf.record.RecordFormatException: Unable to constr
> uct record instance
>         at
> org.apache.poi.hssf.record.RecordFactory$ReflectionRecordCreator.create(RecordFactory.jav
> a:64)
>         at
> org.apache.poi.hssf.record.RecordFactory.createSingleRecord(RecordFactory.java:263)
>         at
> org.apache.poi.hssf.record.RecordFactoryInputStream.readNextRecord(RecordFactoryInputStre
> am.java:270)
>         at
> org.apache.poi.hssf.record.RecordFactoryInputStream.nextRecord(RecordFactoryInputStream.j
> ava:236)
>         at
> org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:377)
>         at
> org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:275)
>         at
> org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:200)
>         at
> org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:316)
>         at
> org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:297)
>         at
> org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:60)
> 
> 
> any idea about how to input file to resource? why does it happen ???
> thanks!
> 

-- 
View this message in context: 
http://old.nabble.com/exception-when-inputstream-is-read-from-getClass%28%29.getClassLoader%28%29.getResourceAsStream%28%22file.xls%22%29-tp26406348p26410285.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@poi.apache.org
For additional commands, e-mail: user-h...@poi.apache.org

Reply via email to