简体   繁体   中英

Java Web Application - File Read

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

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..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM