Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
Hi,

I have some image files in c://images/flower.jpg

I have used following code to read the input stream of the file.
Java
InputStream in = null;
FileInputStream fis = new FileInputStream("c://images/flower.jpg");
in  = fis;
fis.close();


But stream always returns Null . Please help me to read the file stream .

Thanks,
Baskar G
Posted
Updated 5-Nov-15 20:23pm
v2
Comments
Afzaal Ahmad Zeeshan 6-Nov-15 8:36am    
Also, that is C directory not D directory.

Try to remove one of the slashes after c:
From
Java
FileInputStream fis = new FileInputStream("c://images/flower.jpg");

to
Java
FileInputStream fis = new FileInputStream("c:/images/flower.jpg");
 
Share this answer
 
Comments
Baskar Gs 6-Nov-15 7:17am    
I have used below code,

1)InputStream in = null;
2)in = new URL(service.getURL("file://c:/images/flower.jpg")).openStream();
3)int bytes = in.read(b);

I have deployed this code in tomcat server which works fine and displays the image.
same code has been deployed in jboss-4.2.1.GA server, which throws a null point exception in line no 3.

What is that problem, how to solve this problem help me.
George Jonsson 6-Nov-15 8:45am    
Sorry, you need to contact the server support for this.
Afzaal Ahmad Zeeshan 6-Nov-15 8:36am    
5ed.
My guess is that you consider the forward slash ("/") to be an escape character that needs to be doubled. It doesn't.

On Microsoft systems, you can use either forward or back slashes. Back slashes need to be doubled; forward slashes do not.

Change your code to either one of:

C++
FileInputStream fis = new FileInputStream("c:/images/flower.jpg");


or

C++
FileInputStream fis = new FileInputStream("c:\\images\\flower.jpg");
 
Share this answer
 
v3
Comments
Afzaal Ahmad Zeeshan 6-Nov-15 8:36am    
5ed.
phil.o 6-Nov-15 9:00am    
5'd.
You can also avoid the backslashes-doubling by prefixing your string with an @.

C#
FileInputStream fis = new FileInputStream(@"c:\images\flower.jpg");
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900