Hector Barbossa
Hector Barbossa

Reputation: 5528

Accessing files from disk in server root

I need to access some files from my jsp pages.So I kept them inside my server Root.But the no of files are likely to increase.So is there a way by which I can access those files from web server root and store them in anywhere in disk ?

Upvotes: 1

Views: 1033

Answers (2)

Nishant
Nishant

Reputation: 55856

You need to get the absolute path of the file. Read it using FileInputStream, write to output stream on JSP.

        String file = "/home/mystorage/media/file.dat";
        FileInputStream fileinputstream = new FileInputStream(file);
        int numberBytes = fileinputstream.available();
        byte bytearray[] = new byte[numberBytes];

        fileinputstream.read(bytearray);

        for(int i = 0; i < numberBytes; i++){
            out.println(bytearray[i]);
        }

        fileinputstream.close();

refer Java2s Reading Binary Data

Upvotes: 2

Brandon Frohbieter
Brandon Frohbieter

Reputation: 18139

you can create a symbolic link.... create a directory in your web root and

  ln -s directory /path/to/files

Upvotes: 2

Related Questions