Skip to content
Snippets Groups Projects
Commit df1459e0 authored by Christopher Bohn's avatar Christopher Bohn :thinking:
Browse files

On write, creates file if it doesn't exist

parent 5f07781f
No related branches found
No related tags found
No related merge requests found
...@@ -67,6 +67,17 @@ public class CSVReaderWriter { ...@@ -67,6 +67,17 @@ public class CSVReaderWriter {
boolean wroteFile = true; boolean wroteFile = true;
ClassLoader classLoader = CSVReaderWriter.class.getClassLoader(); ClassLoader classLoader = CSVReaderWriter.class.getClassLoader();
URL resource = classLoader.getResource("csv/" + filename); URL resource = classLoader.getResource("csv/" + filename);
if (resource == null) {
try {
String s = Objects.requireNonNull(classLoader.getResource(("csv/"))).getFile();
File f = new File(s, filename);
//noinspection ResultOfMethodCallIgnored
f.createNewFile();
} catch (IOException ioException) {
System.err.println("Error creating " + filename + ". " + ioException);
}
resource = classLoader.getResource("csv/" + filename);
}
if (resource != null) { if (resource != null) {
File file = new File(resource.getPath()); File file = new File(resource.getPath());
try (FileWriter fileWriter = new FileWriter(file)) { try (FileWriter fileWriter = new FileWriter(file)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment