• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

how to access an external file into a web application

 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want access to a file(image) into my web application, this file will not be in my .war file i want to access this file.

i came to know one of the way is to specify the particular file in the web.xml file and then by calling the this.class.getResource() is this a valid way of access an external file, because i am unable to figure out which is the particular tag to achieve this.

is there any other way.

can one help me in this issue.
 
Marshal
Posts: 67447
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An external file will have to have its filer path known, and you would use normal Java File I/O to access it. It could then be streamed as the response if desired.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that the best thing is create a properties file and set a variable path to your file

then you can read the filesystem path to your image from this properties file.
For reading properties file you can use ResourceBoundle.

Enrico
 
Ranch Hand
Posts: 282
Eclipse IDE PHP Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

saipraneeth nallapareddy wrote:i came to know one of the way is to specify the particular file in the web.xml file and then by calling the this.class.getResource() is this a valid way of access an external file, because i am unable to figure out which is the particular tag to achieve this.



This technique requires that the file be inside the classpath of the application, which means that it will be packaged up in the WAR along with all the application's class files. The String that you pass into getResource() is the path to the file. For example, if I put an image inside of the "com.example.images" package, I can access the file like so:

 
saipraneeth nallapareddy
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you every one for the replies

@Bear Bibeault

An external file will have to have its filer path known, and you would use normal Java File I/O to access it. It could then be streamed as the response if desired.



thank you it was the way i implemented it, made use of FileInputStream and convert into buffer and write it to a OutpuStream, it did worked.

@Michael Angstadt

I got the point what you have tried to convey, useful one thank you.
 
I RELEASE YOU! (for now .... ) Feel free to peruse this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic