mohammedirfan655
mohammedirfan655

Reputation: 49

Accessing File Stored on a server in my servlet

In my servlet file im trying to access a file stored on the server,and then im converting it to inputstream and storing it into the database. if I try with local file,Its doing well,but when I try to access the file stored in my server it is showing 500 exception. that the directory cannot be identified.

Note : when I copy this directory and paste it in url,its working fine and showing the image.

Here is my code,

InputStream inputStream = null;        
  inputStream =  new FileInputStream("http://www.example.com/images/community.gif");  

and this is for local,

 inputStream =  new FileInputStream("D:/INDIGOWORK/PostFreeAd/WebContent/images/community.gif");

Its working fine.Please solve my problem

Upvotes: 1

Views: 199

Answers (2)

icza
icza

Reputation: 417572

Try using URL:

InputStream in = new URL("http://www.example.com/images/community.gif")
    .openStream();

Upvotes: 1

Scary Wombat
Scary Wombat

Reputation: 44824

try

http://docs.oracle.com/javase/7/docs/api/java/net/URL.html#openStream()

InputStream input = new URL("http://yourSite/images/community.gif").openStream();

Upvotes: 0

Related Questions