I am newbie in java. I need some suggestion that checking file already existing in folder if not exist then upload file else message in java.
Please give me some example
I have done this let me know how to compare old object and new object.
public Reaction updateEchemReaction(Reaction reaction) {
LOGGER.info("updateEchemReaction(Reaction reaction) called");
entityManager.find(Reaction.class, reaction);
Reaction oldObject = entityManager.find(Reaction.class, reaction);
System.out.println("oldObject==========>>"+oldObject.getFileUpload());
try {
//if (oldObject == null) {
if (reaction != null && reaction.getFileUpload() != null
&& reaction.getFileUpload().size() > 0) {
Set<UUID> fileids = filesUploadBean.updateFiles(
reaction.getFileUpload(), reaction.getLabId());
Set<UUID> fileidsNew = new HashSet<>();
fileidsNew.addAll(fileids);
if (reaction.getFileIds() != null) {
fileidsNew.addAll(reaction.getFileIds());
}
reaction.setFileIds(fileidsNew);
}
//}
} catch (Exception e) {
LOGGER.error(e.getMessage());
}
Check if folder exists && file exist or not, where filePathHere- folder to check
// Compare objects - implement Comparable and implmement compareTo method, not in code below but add null checks too, check ids or whatever java class fields you like.