I have a file test.txt
in the resources folder of my project, and I'm trying to write a List of strings to it, one for each line (from a test class, if it matters).
For some reason, despite no exception being thrown or caught, I've tried many things but I'm not being able to write to it. For example:
Path p = Paths.get(ClassLoader.getSystemResource("test.txt").toURI());
try (BufferedWriter writer = Files.newBufferedWriter(p))
{
for (String line : lines) writer.write(line);
}
catch (IOException e)
{
e.printStackTrace();
}
Files.write(p, lines)
does not work either. I'm perplexed because no error is reported but the file remains empty. I also made sure the path is recognized with p.toFile().exists()
, and it does return true
. What am I missing?