user850234 user850234 - 2 years ago 90
Apache Configuration Question

Create folders programatically along with permissions using java to save content to that location

I have xampp installed in my windows system and lampp installed in my linux system. I want to create folder in the location "http://localhost/" using java. I have done the following :

dirName = new File("http://localhost/"+name);
if(!dirName.exists()) {

Is it possible to do? The idea is to download some files to that location programatically. Download is working but how do i create folders so that i can access it via
. This is required to keep track of the user related content. I have access to the apache web server with lampp already installed. How can i create folders and save the downloads to that folder with programatically assigning the permissions to the folder and contents within it so that saved contents can be download from there using

Answer Source

In Java you can create files in any writeable directory on your system by doing something like:

File file1 = new File("/var/www/newDirectory/");

Then to create a file in that directory you can do something like this:

File file2 = new File(file1.getAbsolutePath() + "newFile.txt"); // You may need to add a "File.seperator()" after the "file1.getAbsolutePath()" if the trailing "/" isn't included
if (file2.exists() == false) {

To ensure that your file is readable to the public you should add read permissions to the file:

file2.setReadable(true, false);

In Apache you can set up a virtual host that points to the directory where you would like to make files available from. By default on debian linux it is /var/www.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download