We encounter errors because we update a read only file. Currently I have a method that soft deletes a file. This method has a parameter DataHandler which has a field that contains an input stream. Would like to ask for some suggestions if there is a way to determine if dataHandler.getInputStream is a ready only. Writing the stream in a file on hard disk is not an option either
Asked
Active
Viewed 355 times
-2
-
I do not understand. You have a method that deletes a file while the file is open (has an input stream)? You're getting errors that tell you the file is read-only and you want to know whether the file is read-only? – user207421 Aug 09 '16 at 01:58
-
I saw almost the same question a few days ago. Is this some kind of assignment? Or are you posting the same question again? -- It was you. You already have an answer on that question. – Erwin Bolwidt Aug 09 '16 at 02:37
1 Answers
2
Your question doesn't actually make any sense. An InputStream is just that - an input - something that you read. You can't write to or delete an InputStream.
If you mean that you are attempting to delete the file which is the source of the InputStream, then you'd have to have a reference to the File object instance to delete it, so you could then check writability using the File's canWrite() method.
However, that's probably not a foolproof way of attempting to delete a File without an exception - you'd have to also catch SecurityException.
Also, you should check the result of delete() to see if the file was actually deleted.

GreyBeardedGeek
- 29,460
- 2
- 47
- 67