• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to access an external file into a web application

 
saipraneeth nallapareddy
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65128
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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.
 
Enrico Oliosi
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
 
Michael Angstadt
Ranch Hand
Posts: 277
Eclipse IDE Java PHP
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic