This question is related to "Java Web Application - File Upload".
Is it possible for a Web Application to read a file from the host file system?
My guess is that for security reasons the answer is no - but I guess it should be possible for it to read files in directories below the root of the application.
If so, could someone supply an example code snippet.
Thanks
views:
31answers:
1
+1
A:
I'm using the Apache Wicket web-framework, deployed on the Glassfish 2 web-app container, and this snippet works fine for me:
//Read file content
FileInputStream in = new FileInputStream(new File("absolute path"));
byte[] bt = new byte[(int) file.length()];
in.read(bt);
in.close();
return bt;
Could however be related to the way the web application server is setup, so your mileage may vary..
Tim
2010-10-03 09:24:37
@Tim Hi. Is "absolute path" below WEB-INF? Or is it a random location of the file system. Did you have to configure special permissions in the security manager?
leftbrainlogic
2010-10-03 09:37:33
It's a random location on the file system.. I've not touched the security manager, so I'm working with whatever the Glassfish instance gave me. I'm not the one administrating this server however, so I can't say what security restrictions are in place (but I have heard rumors saying it's run as root.. =\)
Tim
2010-10-03 17:09:05