This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes IO - POI - HSSF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "IO - POI - HSSF" Watch "IO - POI - HSSF" New topic
Author

IO - POI - HSSF

Seba Lenoir
Greenhorn

Joined: Jan 17, 2003
Posts: 5
Hello,
I'm trying to use Apache POI to parse a XLS file with java.
When the file is in local I can do:
1 File file = new File("c:\\afile.xls");
2 InputStream is = file.toURL().openStream();
3 POIFSFileSystem fs = new POIFSFileSystem(is);
4 HSSFWorkbook wb = new HSSFWorkbook(fs);
without any problems.
It is working very well.
But when the file is on the web, I ave an instance of an HttpURLConnection to access it.
When I try the folloing:
1 InputStream is = httpURLCon.getUrl().openStream();
2 POIFSFileSystem fs = new POIFSFileSystem(is);
3 HSSFWorkbook wb = new HSSFWorkbook(fs);
I get a FileNotFoundException in line 3.
Does anyone knows a way to avoid this problem?
Thanks
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
Maybe your URL isn't correct...but we can't tell b/c we can't see that...
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
I think we should better verify whether the file we are going to use really exist or the path that we specify is correct by using yourFileObj.exists(). And then do things in the if statement... For instance,


Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: IO - POI - HSSF
 
Similar Threads
How tochange the values in an existing Excel file by using POI?
POI excel rewrite file
Read a .xls,.xlsx file format using XSSF
Reading Excel File
use Apache POI to read Excel file problem