java - How to wait in the same thread while file is being written to, to finish, so we can use it -
i have file open , write situation crashes eofexception once in 20-30 times, because file unavailable because other process writing it.
can catch exception, somehow wait file write operation synchronously end, can recurse method?
file productjson = getfilestreampath("product" + "_" + getid() + ".json"); if (!productjson.exists()) { productjson = getfilestreampath("product" + ".json"); } inputstream jsonstringsfileinputstream; try { jsonstringsfileinputstream = new fileinputstream(productjson); hashmap<string, map> = new jsontoproductparser().convertthistothat(jsonstringsfileinputstream); } catch (filenotfoundexception e) { e.printstacktrace(); }
you can check file write access before opening it.this done canwrite() method.
also check out solved question. deals synchronized attribute.
Comments
Post a Comment