Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

InputStream Help

Status
Not open for further replies.

klaforce

Programmer
Mar 25, 2005
124
US
I am using Java to create a CFX tag in Coldfusion to read an Excel File, but I am having trouble opening the file using InputStream. I have the following code:

response.write(file + "<BR>");
InputStream myxls = new FileInputStream(file.toString());

(where response.write writes to the browser, and the string file comes in from request) If I hard code the path like this:

InputStream myxls = new FileInputStream("C:\\CFusionMX\\ Traffic Flow Team Action Register.xls");

it works great, but in I use the variable file (which holds the same value I hardcoded) it will not work. Does anyone have any suggestions? Thanks for your help.
 
Also, the exception thrown is java.io.FileNotFoundException
 
post the stack trace (so we can see the file name its trying to load)

--------------------------------------------------
Free Database Connection Pooling Software
 
Well, once I did that I found the error quickly. Thanks for your help.

Keith
 
I recommend using File.separatorChar rather then \\ in paths
 
Oh, I have never heard of File.separatorChar. Why is it better?
 
It uses the default separator of the OS. So under Unix it would be /, under Windows \ and so if you use relative paths you dont have to change that when moving between OS. Also you dont have to escape it so no chance of messing up there.

There are exceptions though (afaik) - I ran into problem with ziping - zip accepts both \ and / but the program that read it was expecting / and I couldnt figure where I went wrong
 
Oh that is awesome, thanks for the tip.

Keith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top