0

名前を指定してファイルに書き込むコードがあります。それを読み取るハッシュマップがあります。これらの書き込みは成功しており、読み取りも成功しています。

しかし、ファイルはどこにもありません。

ここに書くコードは次のとおりです。

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);
    }
}

そしてここに読書があります:

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);
    }
}

説明したいですか?

4

1 に答える 1

0

で確認してくださいnew File(url).exists();

于 2013-11-10T07:48:35.753 に答える