0

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!

StriplingWarrior
  • 151,543
  • 27
  • 246
  • 315
smurfMT
  • 124
  • 10
  • what is the error that you see ? – Mzf Apr 24 '14 at 15:41
  • there is no error, or exception being thrown, its just not writing to the file in question – smurfMT Apr 24 '14 at 15:42
  • is it just a difference in read vs write permissions on the file / directory? – Graham Griffiths Apr 24 '14 at 15:42
  • ill check now and post results – smurfMT Apr 24 '14 at 15:44
  • It might be writing in the classes directory. For example if you are using maven to build your project, see if it is getting generated in {PROJECT_DIR}/target/classes – Amit Apr 24 '14 at 15:45
  • You can have a look at: http://stackoverflow.com/questions/17554085/how-to-create-a-file-in-src-main-resources – user2754805 Apr 24 '14 at 15:47
  • 4
    It totally depends on the context of your app. If you run from the root directory of the project of course you can--but it may not be doing what you actually *think* it is, and you almost certainly should *not* write to the *source of your program* from within that program. – Dave Newton Apr 24 '14 at 15:51

0 Answers0