Leer un archivo de Amazon EBS

I want to download a file from one of the EBS volumes I created on Amazon Elastic block storage. Mostly it is advisable to used ServletContext#getResource() y su contraparte ServletContext#getResourceAsStream() as well advised aquí.

But in this case is the following code advisable

InputStream in = new FileInputStream(new File(FOLDER_PATH_ON_AMAZON_EBS + "/" + folder + "/" + fileName));

preguntado el 29 de julio de 12 a las 23:07

2 Respuestas

It's hard to tell what the question is here.

If you are asking whether it is better to use getServletContext() or new File(PATH_TO_EBS...) then it simply depends on what you are running. If you are running a standalone java application and requesting files via sockets, then you would use the latter (a FileInputStream over a file you know where to look). If you are running a web server (eg Tomcat) and will be using a web client to download the file, then you would typically use the getServletContext() since that is part of the web-server infrastructure.

Both ways let you get a handle on the file, but getServletContext() is going to refer to a location for your application under Tomcat's working area. Are you going to mount your EBS volume somewhere where you can easily reach it starting from Tomcat's working area.

If you are running a web server and it is allowing you to reach a file directly in your EBS volume with new FileInputStream(new File(MY_EBS_LOCATION + "/" + ...)) then use it by all means - clear and easy.

Respondido 07 ago 12, 09:08

Having the file path in the properties file, and using the absolute path is better due the following reasons,

  • There are chances that the mountpoint of the ec2 volume changes, having that in the classpath and modifying that is comparatively harder than modifying the entry in the properties file.
  • Normally resources like property files are got using getResource(), if there is going to be other IO like storing photos, office docs then its wise to use absolute path for access.

It also depends on the usecase if the files(resource) is frequently used by the application, and the application only, then u can have that in classpath and pack it along with the archive.

Respondido 02 ago 12, 12:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.