there is a code that write to a file by given a name. there is a hash map that read form it. thew writing is passing successful, also reading from it.
but the file is no where to be found.
here is the code that writes:
public void attachUrlToGuid(String url, String guid) {
ObjectMapper mapper = new ObjectMapper();
fileList.put(url, guid);// doesn't matter if url already exist or have a different guid - just replacing with the new value.
try{
fileWriter = new FileWriter(fileName);
mapper.writeValue(fileWriter, fileList);
}
catch (IOException e){//in case of failure and the file did not get updated, then in the next upload file it will be written due to keeping HM alive.
LOGGER.error(ERROR_MSG_WRITE_TO_FILE);
}
}
and here is the reading:
static{
ObjectMapper mapper = new ObjectMapper();
try{
fileReader = new FileReader(fileName);
fileList = mapper.readValue(fileReader, HashMap.class);
}
catch (FileNotFoundException e){//in case file does not exist
fileList = new HashMap<String, String>();
}
catch (IOException e){
LOGGER.error(ERROR_MSG_INVALID_DATA);
}
}
care to explain?