How to only open an existing file in java -


this question has answer here:

i know how open file in java writing, want open if exists already. possible? i've searched around , found 2 suggestions far both don't meet needs. 1 open file appending. problem there if file doesn't exist create it. second use file.exists() first. of course not valid solution file may exist when call file.exists() not exist when go open file. want similar windows api openfile() in can pass open_existing flag such call fail file doesn't exists. exist in java?

only editing question because marked duplicate. not sure why. thought pretty specific other answers , why not sufficient.

so i'll restate, want open file writing. want open fail if file doesn't exist.

exists() returns true if file path valid directory if file isn't there. can around using:

file f = new file(filepathstring);  if(f.exists() && !f.isdirectory()) {/*do whatever*/} 

or use:

file f = new file(filepathstring);  if f.isfile() {/*do whatever*/} 

Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -