Can you write to a file in src/main/resources?

吃可爱长大的小学妹 提交于 2019-12-12 04:46:06

问题


Question is in the Title, Here's my code which dosen't seem to work:

    File counterValues = new File(getClass().getResource(COUNTER_VALUES_FILE).getFile());      
    FileWriter out = new FileWriter(counterValues);

    out.write("TEST");

    out.close();

where COUNTER_VALUES_FILE is private static final String COUNTER_VALUES_FILE = "/data/counter_values.csv";

I have also tried:

    File counterValues = new File(getClass().getResource(COUNTER_VALUES_FILE).toURI());

It has made me believe it might not be possible, but i don't see why not if i can read from the file!

来源:https://stackoverflow.com/questions/23273562/can-you-write-to-a-file-in-src-main-resources

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!