java


How to prevent someone from deleting files that my program is currently using?


I have a program that temporarily saves some Objects to my Hard-Disk only to be re-loaded a few minutes after:
This is the method:
private void save(Object myObject, String path) throws IOException {
final BufferedOutputStream bf = new BufferedOutputStream(
new FileOutputStream(path));
final ObjectOutputStream objOut = new ObjectOutputStream(bf);
objOut.writeUnshared(myObject);
bf.close();
bf.flush();
objOut.flush();
objOut.reset();
}
The problem is that I'm able to delete the file from the disk at runtime, and ending up in a NoSuchFileException later:
How to prevent this from happening?
I also tried using
objOut.writeObject(myObject);
instead of
objOut.writeUnshared(myObject);
but still nothing...
Can someone help me? Thanks!
EDIT Read comments for a more detailed description of the request!
Basically you can't but you can mitigate this problem as follow:
create a specific system user to execute your java application
create a folder visible only to that system user
launch your java app with that user
This mitigate the problem because a human can always log a the system user defined before so having full control over the private files.
You can also hide the directory where you save the files to make more hard for a human to delete them.

Related Links

Using Hibernate with MS SQL and domain user
Apache-HttpClient/UNAVAILABLE (java 1.4)
Move object up/down with swipe gesture
Strange behavior using Java ternary operator on Android
Check two conditions with two different outcomes (ternary operators)
How to make a certain file openable with your own program?
How to check if argument is varArgs
Android modify imported library via gradle
Java - How to read multiple values from the same line
Java Selenium WebDriver unable to place first item into basket
Getting a null-point exception in Neo4j data retrieval
Frequency capped sum in Elasticsearch
Defining 3rd-party library in Wildfly as Module without including its dependencies
Setter for LocalDateTime (Java 8 API) gets called twice
OOP - How does one class become another?
Error when I try to write in mongo setCollectionSharded:already sharded

Categories

HOME
ibm-bluemix
ionic-framework
angular-material
plot
objectgears
cplex
maven-3
yarn
paw-app
graphql
webpack-2
disassembler
blueprintjs
azure-storage-tables
qore
synchronization
session-variables
spring-xd
quicklook
qt-creator
nstableview
correlation
task
try-catch
swingx
cx-freeze
riot.js
kvc
traffic
fluentvalidation
jaxb2
windowbuilder
file-rename
sql-server-2012-express
google-cloud-endpoints-v2
pdb
force-layout
gesture
tasker
dism
mesos-chronos
unoconv
sql-server-agent
password-encryption
reactive-cocoa-5
websphere-mq-fte
jedis
dds
knockout-components
ableton-live
static-ip-address
vmware-tools
mikroc
holder.js
simplewebrtc
moveit
bluemix-app-scan
pagerank
xna-4.0
jms2
cyclomatic-complexity
mutation-observers
tarjans-algorithm
mono-embedding
createprocessasuser
streambase
bridge.net
umbraco6
google-style-guide
java.util.concurrent
file-copying
fpml
nsbutton
flask-cors
valuechangelistener
comexception
bundles
mcts
dataservice
free-variable
tinn-r
nsnetservice
enter
jquery-ui-layout
spring-portlet-mvc
cufon
subgurim-maps
hamachi
xmemcached
imac
audio-capture
ctp4
procedural-music

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile