java - Creating read only file when download -


my requirement upload file in read format using spring mvc , download same file in read only. able upload file in read format after download lost read property.

code file upload :-

file destinationfile = new file ( targetpath);  try {     fileoutputstream out = new fileoutputstream( destinationfile );      byte[] bytes = file.getbytes();     stream = new bufferedoutputstream(out);     stream.write(bytes);      destinationfile.setreadonly();     destinationfile.setwritable(false);  }finally {     if(stream != null){         stream.close();     } }  

code download :-

file file = new file(folderpath); contenttype = "application/octet-stream";  response.setbuffersize(buffer_size); response.setheader("content-disposition", disposition + ";filename=\"" + filename  + "\"");  randomaccessfile input = new randomaccessfile(file, "r"); outputstream output = response.getoutputstream(); long start, long length;  byte[] buffer = new byte[buffer_size]; int read;  if (input.length() == length) {     while ((read = input.read(buffer)) > 0) {         output.write(buffer, 0, read);     } } else {     input.seek(start);     long toread = length;      while ((read = input.read(buffer)) > 0) {         if ((toread -= read) > 0) {             output.write(buffer, 0, read);         } else {             output.write(buffer, 0, (int) toread + read);             break;         }     } } 

any suggestion ?

unfortunately impossible.

once file on user's machine not control cannot enforce file.

you can sign key detect tampering, still able edit it, know have done it.

you cannot set read-only flag, question confirms, there no read header, , if made downloader respected header, , set flag on file user remove read flag file , able edit it.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -